user_default.rs 1.8 KB

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