row_entities.rs 1.9 KB

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