app_create.rs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. use crate::{
  2. entities::{
  3. app::parser::{AppColorStyle, AppName},
  4. view::RepeatedView,
  5. workspace::parser::WorkspaceId,
  6. },
  7. errors::*,
  8. impl_def_and_def_mut,
  9. };
  10. use flowy_derive::ProtoBuf;
  11. use std::convert::TryInto;
  12. #[derive(ProtoBuf, Default)]
  13. pub struct CreateAppRequest {
  14. #[pb(index = 1)]
  15. pub workspace_id: String,
  16. #[pb(index = 2)]
  17. pub name: String,
  18. #[pb(index = 3)]
  19. pub desc: String,
  20. #[pb(index = 4)]
  21. pub color_style: ColorStyle,
  22. }
  23. #[derive(ProtoBuf, Default, Debug, Clone)]
  24. pub struct ColorStyle {
  25. #[pb(index = 1)]
  26. pub theme_color: String,
  27. }
  28. #[derive(ProtoBuf, Default, Debug)]
  29. pub struct CreateAppParams {
  30. #[pb(index = 1)]
  31. pub workspace_id: String,
  32. #[pb(index = 2)]
  33. pub name: String,
  34. #[pb(index = 3)]
  35. pub desc: String,
  36. #[pb(index = 4)]
  37. pub color_style: ColorStyle,
  38. }
  39. impl TryInto<CreateAppParams> for CreateAppRequest {
  40. type Error = WorkspaceError;
  41. fn try_into(self) -> Result<CreateAppParams, Self::Error> {
  42. let name = AppName::parse(self.name).map_err(|e| WorkspaceError::app_name().context(e))?;
  43. let id = WorkspaceId::parse(self.workspace_id).map_err(|e| WorkspaceError::workspace_id().context(e))?;
  44. let color_style = AppColorStyle::parse(self.color_style).map_err(|e| WorkspaceError::color_style().context(e))?;
  45. Ok(CreateAppParams {
  46. workspace_id: id.0,
  47. name: name.0,
  48. desc: self.desc,
  49. color_style: color_style.0,
  50. })
  51. }
  52. }
  53. #[derive(PartialEq, ProtoBuf, Default, Debug, Clone)]
  54. pub struct App {
  55. #[pb(index = 1)]
  56. pub id: String,
  57. #[pb(index = 2)]
  58. pub workspace_id: String,
  59. #[pb(index = 3)]
  60. pub name: String,
  61. #[pb(index = 4)]
  62. pub desc: String,
  63. #[pb(index = 5)]
  64. pub belongings: RepeatedView,
  65. #[pb(index = 6)]
  66. pub version: i64,
  67. #[pb(index = 7)]
  68. pub modified_time: i64,
  69. #[pb(index = 8)]
  70. pub create_time: i64,
  71. }
  72. #[derive(PartialEq, Debug, Default, ProtoBuf, Clone)]
  73. pub struct RepeatedApp {
  74. #[pb(index = 1)]
  75. pub items: Vec<App>,
  76. }
  77. impl_def_and_def_mut!(RepeatedApp, App);