workspace.rs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. use crate::entities::workspace::{CreateWorkspaceParams, UpdateWorkspaceParams, WorkspaceDetail};
  2. use flowy_database::schema::workspace_table;
  3. use flowy_infra::{timestamp, uuid};
  4. use serde::{Deserialize, Serialize};
  5. #[derive(PartialEq, Clone, Serialize, Deserialize, Debug, Queryable, Identifiable, Insertable)]
  6. #[table_name = "workspace_table"]
  7. #[serde(tag = "type")]
  8. pub struct Workspace {
  9. pub id: String,
  10. pub name: String,
  11. pub desc: String,
  12. pub modified_time: i64,
  13. pub create_time: i64,
  14. pub user_id: String,
  15. pub version: i64,
  16. }
  17. impl Workspace {
  18. #[allow(dead_code)]
  19. pub fn new(params: CreateWorkspaceParams) -> Self {
  20. let mut workspace = Workspace::default();
  21. workspace.name = params.name;
  22. workspace.desc = params.desc;
  23. workspace
  24. }
  25. }
  26. impl std::default::Default for Workspace {
  27. fn default() -> Self {
  28. let time = timestamp();
  29. Workspace {
  30. id: uuid(),
  31. name: String::default(),
  32. desc: String::default(),
  33. modified_time: time,
  34. create_time: time,
  35. user_id: String::default(),
  36. version: 0,
  37. }
  38. }
  39. }
  40. #[derive(AsChangeset, Identifiable, Clone, Default, Debug)]
  41. #[table_name = "workspace_table"]
  42. pub struct WorkspaceChangeset {
  43. pub id: String,
  44. pub name: Option<String>,
  45. pub desc: Option<String>,
  46. }
  47. impl WorkspaceChangeset {
  48. pub fn new(params: UpdateWorkspaceParams) -> Self {
  49. WorkspaceChangeset {
  50. id: params.id,
  51. name: params.name,
  52. desc: params.desc,
  53. }
  54. }
  55. }
  56. impl std::convert::Into<WorkspaceDetail> for Workspace {
  57. fn into(self) -> WorkspaceDetail {
  58. WorkspaceDetail {
  59. id: self.id,
  60. name: self.name,
  61. desc: self.desc,
  62. }
  63. }
  64. }