app_create.rs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. use crate::{
  2. entities::view::RepeatedView,
  3. errors::*,
  4. impl_def_and_def_mut,
  5. parser::{
  6. app::{AppColorStyle, AppName},
  7. workspace::WorkspaceId,
  8. },
  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 = ErrorCode;
  41. fn try_into(self) -> Result<CreateAppParams, Self::Error> {
  42. let name = AppName::parse(self.name)?;
  43. let id = WorkspaceId::parse(self.workspace_id)?;
  44. let color_style = AppColorStyle::parse(self.color_style.theme_color.clone())?;
  45. Ok(CreateAppParams {
  46. workspace_id: id.0,
  47. name: name.0,
  48. desc: self.desc,
  49. color_style: color_style.into(),
  50. })
  51. }
  52. }
  53. impl std::convert::From<AppColorStyle> for ColorStyle {
  54. fn from(data: AppColorStyle) -> Self {
  55. ColorStyle {
  56. theme_color: data.theme_color,
  57. }
  58. }
  59. }
  60. #[derive(PartialEq, ProtoBuf, Default, Debug, Clone)]
  61. pub struct App {
  62. #[pb(index = 1)]
  63. pub id: String,
  64. #[pb(index = 2)]
  65. pub workspace_id: String,
  66. #[pb(index = 3)]
  67. pub name: String,
  68. #[pb(index = 4)]
  69. pub desc: String,
  70. #[pb(index = 5)]
  71. pub belongings: RepeatedView,
  72. #[pb(index = 6)]
  73. pub version: i64,
  74. #[pb(index = 7)]
  75. pub modified_time: i64,
  76. #[pb(index = 8)]
  77. pub create_time: i64,
  78. }
  79. impl App {
  80. pub fn take_belongings(&mut self) -> RepeatedView { std::mem::take(&mut self.belongings) }
  81. }
  82. #[derive(PartialEq, Debug, Default, ProtoBuf, Clone)]
  83. pub struct RepeatedApp {
  84. #[pb(index = 1)]
  85. pub items: Vec<App>,
  86. }
  87. impl_def_and_def_mut!(RepeatedApp, App);