row_entities.rs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. use flowy_derive::ProtoBuf;
  2. use flowy_error::ErrorCode;
  3. use flowy_grid_data_model::parser::NotEmptyStr;
  4. #[derive(Debug, Default, Clone, ProtoBuf)]
  5. pub struct GridRowIdPB {
  6. #[pb(index = 1)]
  7. pub grid_id: String,
  8. #[pb(index = 2)]
  9. pub block_id: String,
  10. #[pb(index = 3)]
  11. pub row_id: String,
  12. }
  13. pub struct GridRowIdParams {
  14. pub grid_id: String,
  15. pub block_id: String,
  16. pub row_id: String,
  17. }
  18. impl TryInto<GridRowIdParams> for GridRowIdPB {
  19. type Error = ErrorCode;
  20. fn try_into(self) -> Result<GridRowIdParams, Self::Error> {
  21. let grid_id = NotEmptyStr::parse(self.grid_id).map_err(|_| ErrorCode::GridIdIsEmpty)?;
  22. let block_id = NotEmptyStr::parse(self.block_id).map_err(|_| ErrorCode::BlockIdIsEmpty)?;
  23. let row_id = NotEmptyStr::parse(self.row_id).map_err(|_| ErrorCode::RowIdIsEmpty)?;
  24. Ok(GridRowIdParams {
  25. grid_id: grid_id.0,
  26. block_id: block_id.0,
  27. row_id: row_id.0,
  28. })
  29. }
  30. }
  31. #[derive(Debug, Default, Clone, ProtoBuf)]
  32. pub struct BlockRowIdPB {
  33. #[pb(index = 1)]
  34. pub block_id: String,
  35. #[pb(index = 2)]
  36. pub row_id: String,
  37. }
  38. #[derive(ProtoBuf, Default)]
  39. pub struct CreateRowPayloadPB {
  40. #[pb(index = 1)]
  41. pub grid_id: String,
  42. #[pb(index = 2, one_of)]
  43. pub start_row_id: Option<String>,
  44. }
  45. #[derive(Default)]
  46. pub struct CreateRowParams {
  47. pub grid_id: String,
  48. pub start_row_id: Option<String>,
  49. }
  50. impl TryInto<CreateRowParams> for CreateRowPayloadPB {
  51. type Error = ErrorCode;
  52. fn try_into(self) -> Result<CreateRowParams, Self::Error> {
  53. let grid_id = NotEmptyStr::parse(self.grid_id).map_err(|_| ErrorCode::GridIdIsEmpty)?;
  54. Ok(CreateRowParams {
  55. grid_id: grid_id.0,
  56. start_row_id: self.start_row_id,
  57. })
  58. }
  59. }