user_default.rs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. use crate::entities::{
  2. app::{App, RepeatedApp},
  3. view::{RepeatedView, View, ViewType},
  4. workspace::Workspace,
  5. };
  6. use chrono::Utc;
  7. pub fn create_default_workspace(time: chrono::DateTime<Utc>) -> Workspace {
  8. let workspace_id = uuid::Uuid::new_v4();
  9. let name = "Workspace".to_string();
  10. let desc = "".to_string();
  11. let apps = RepeatedApp {
  12. items: vec![create_default_app(workspace_id.to_string(), time.clone())],
  13. };
  14. let workspace = Workspace {
  15. id: workspace_id.to_string(),
  16. name,
  17. desc,
  18. apps,
  19. modified_time: time.timestamp(),
  20. create_time: time.timestamp(),
  21. };
  22. workspace
  23. }
  24. fn create_default_app(workspace_id: String, time: chrono::DateTime<Utc>) -> App {
  25. let app_id = uuid::Uuid::new_v4();
  26. let name = "⭐️ Getting started".to_string();
  27. let desc = "".to_string();
  28. let views = RepeatedView {
  29. items: vec![create_default_view(app_id.to_string(), time.clone())],
  30. };
  31. App {
  32. id: app_id.to_string(),
  33. workspace_id,
  34. name,
  35. desc,
  36. belongings: views,
  37. version: 0,
  38. modified_time: time.timestamp(),
  39. create_time: time.timestamp(),
  40. }
  41. }
  42. fn create_default_view(app_id: String, time: chrono::DateTime<Utc>) -> View {
  43. let view_id = uuid::Uuid::new_v4();
  44. let name = "Read me".to_string();
  45. let desc = "".to_string();
  46. let view_type = ViewType::Doc;
  47. View {
  48. id: view_id.to_string(),
  49. belong_to_id: app_id,
  50. name,
  51. desc,
  52. view_type,
  53. version: 0,
  54. belongings: Default::default(),
  55. modified_time: time.timestamp(),
  56. create_time: time.timestamp(),
  57. }
  58. }