workspace_create.rs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. use crate::{
  2. entities::{app::RepeatedApp, workspace::parser::*},
  3. errors::*,
  4. impl_def_and_def_mut,
  5. };
  6. use flowy_derive::ProtoBuf;
  7. use std::convert::TryInto;
  8. #[derive(ProtoBuf, Default)]
  9. pub struct CreateWorkspaceRequest {
  10. #[pb(index = 1)]
  11. pub name: String,
  12. #[pb(index = 2)]
  13. pub desc: String,
  14. }
  15. #[derive(ProtoBuf, Default)]
  16. pub struct CreateWorkspaceParams {
  17. #[pb(index = 1)]
  18. pub name: String,
  19. #[pb(index = 2)]
  20. pub desc: String,
  21. #[pb(index = 3, one_of)]
  22. pub user_id: Option<String>,
  23. }
  24. impl TryInto<CreateWorkspaceParams> for CreateWorkspaceRequest {
  25. type Error = WorkspaceError;
  26. fn try_into(self) -> Result<CreateWorkspaceParams, Self::Error> {
  27. let name = WorkspaceName::parse(self.name).map_err(|e| {
  28. ErrorBuilder::new(WsErrCode::WorkspaceNameInvalid)
  29. .msg(e)
  30. .build()
  31. })?;
  32. Ok(CreateWorkspaceParams {
  33. name: name.0,
  34. desc: self.desc,
  35. user_id: None,
  36. })
  37. }
  38. }
  39. #[derive(PartialEq, ProtoBuf, Default, Debug)]
  40. pub struct Workspace {
  41. #[pb(index = 1)]
  42. pub id: String,
  43. #[pb(index = 2)]
  44. pub name: String,
  45. #[pb(index = 3)]
  46. pub desc: String,
  47. #[pb(index = 4)]
  48. pub apps: RepeatedApp,
  49. }
  50. impl Workspace {
  51. pub fn new(id: String, name: String, desc: String) -> Self {
  52. Self {
  53. id,
  54. name,
  55. desc,
  56. apps: RepeatedApp::default(),
  57. }
  58. }
  59. }
  60. #[derive(PartialEq, Debug, Default, ProtoBuf)]
  61. pub struct Workspaces {
  62. #[pb(index = 1)]
  63. pub items: Vec<Workspace>,
  64. }
  65. impl_def_and_def_mut!(Workspaces, Workspace);