app_create.rs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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).map_err(|e| {
  38. ErrorBuilder::new(WorkspaceErrorCode::AppNameInvalid)
  39. .msg(e)
  40. .build()
  41. })?;
  42. let id = WorkspaceId::parse(self.workspace_id).map_err(|e| {
  43. ErrorBuilder::new(WorkspaceErrorCode::WorkspaceIdInvalid)
  44. .msg(e)
  45. .build()
  46. })?;
  47. let color_style = AppColorStyle::parse(self.color_style).map_err(|e| {
  48. ErrorBuilder::new(WorkspaceErrorCode::AppColorStyleInvalid)
  49. .msg(e)
  50. .build()
  51. })?;
  52. Ok(CreateAppParams {
  53. workspace_id: id.0,
  54. name: name.0,
  55. desc: self.desc,
  56. color_style: color_style.0,
  57. })
  58. }
  59. }
  60. #[derive(PartialEq, ProtoBuf, Default, Debug)]
  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 views: RepeatedView,
  72. }
  73. #[derive(Debug, Default, ProtoBuf)]
  74. pub struct RepeatedApp {
  75. #[pb(index = 1)]
  76. pub items: Vec<App>,
  77. }
  78. impl_def_and_def_mut!(RepeatedApp, App);