user_default.rs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. use crate::entities::{
  2. app::{App, RepeatedApp},
  3. view::{RepeatedView, View, ViewDataType},
  4. workspace::Workspace,
  5. };
  6. use chrono::Utc;
  7. pub fn create_default_workspace() -> Workspace {
  8. let time = Utc::now();
  9. let workspace_id = uuid::Uuid::new_v4();
  10. let name = "Workspace".to_string();
  11. let desc = "".to_string();
  12. let apps = RepeatedApp {
  13. items: vec![create_default_app(workspace_id.to_string(), time)],
  14. };
  15. Workspace {
  16. id: workspace_id.to_string(),
  17. name,
  18. desc,
  19. apps,
  20. modified_time: time.timestamp(),
  21. create_time: time.timestamp(),
  22. }
  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)],
  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 data_type = ViewDataType::TextBlock;
  47. View {
  48. id: view_id.to_string(),
  49. belong_to_id: app_id,
  50. name,
  51. desc,
  52. data_type,
  53. version: 0,
  54. belongings: Default::default(),
  55. modified_time: time.timestamp(),
  56. create_time: time.timestamp(),
  57. ext_data: "".to_string(),
  58. thumbnail: "".to_string(),
  59. plugin_type: 0,
  60. }
  61. }