app_create.rs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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)]
  24. pub struct ColorStyle {
  25. #[pb(index = 1)]
  26. pub theme_color: String,
  27. }
  28. pub struct CreateAppParams {
  29. pub workspace_id: String,
  30. pub name: String,
  31. pub desc: String,
  32. pub color_style: ColorStyle,
  33. }
  34. impl TryInto<CreateAppParams> for CreateAppRequest {
  35. type Error = WorkspaceError;
  36. fn try_into(self) -> Result<CreateAppParams, Self::Error> {
  37. let name = AppName::parse(self.name)
  38. .map_err(|e| ErrorBuilder::new(WsErrCode::AppNameInvalid).msg(e).build())?;
  39. let id = WorkspaceId::parse(self.workspace_id).map_err(|e| {
  40. ErrorBuilder::new(WsErrCode::WorkspaceIdInvalid)
  41. .msg(e)
  42. .build()
  43. })?;
  44. let color_style = AppColorStyle::parse(self.color_style).map_err(|e| {
  45. ErrorBuilder::new(WsErrCode::AppColorStyleInvalid)
  46. .msg(e)
  47. .build()
  48. })?;
  49. Ok(CreateAppParams {
  50. workspace_id: id.0,
  51. name: name.0,
  52. desc: self.desc,
  53. color_style: color_style.0,
  54. })
  55. }
  56. }
  57. #[derive(PartialEq, ProtoBuf, Default, Debug)]
  58. pub struct App {
  59. #[pb(index = 1)]
  60. pub id: String,
  61. #[pb(index = 2)]
  62. pub workspace_id: String,
  63. #[pb(index = 3)]
  64. pub name: String,
  65. #[pb(index = 4)]
  66. pub desc: String,
  67. #[pb(index = 5)]
  68. pub views: RepeatedView,
  69. }
  70. #[derive(Debug, Default, ProtoBuf)]
  71. pub struct RepeatedApp {
  72. #[pb(index = 1)]
  73. pub items: Vec<App>,
  74. }
  75. impl_def_and_def_mut!(RepeatedApp, App);