calendar_entities.rs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. use flowy_derive::{ProtoBuf, ProtoBuf_Enum};
  2. use flowy_error::ErrorCode;
  3. use crate::entities::parser::NotEmptyStr;
  4. use crate::services::setting::{CalendarLayout, CalendarLayoutSetting};
  5. #[derive(Debug, Clone, Eq, PartialEq, Default, ProtoBuf)]
  6. pub struct CalendarLayoutSettingPB {
  7. #[pb(index = 1)]
  8. pub field_id: String,
  9. #[pb(index = 2)]
  10. pub layout_ty: CalendarLayoutPB,
  11. #[pb(index = 3)]
  12. pub first_day_of_week: i32,
  13. #[pb(index = 4)]
  14. pub show_weekends: bool,
  15. #[pb(index = 5)]
  16. pub show_week_numbers: bool,
  17. }
  18. impl std::convert::From<CalendarLayoutSettingPB> for CalendarLayoutSetting {
  19. fn from(pb: CalendarLayoutSettingPB) -> Self {
  20. CalendarLayoutSetting {
  21. layout_ty: pb.layout_ty.into(),
  22. first_day_of_week: pb.first_day_of_week,
  23. show_weekends: pb.show_weekends,
  24. show_week_numbers: pb.show_week_numbers,
  25. field_id: pb.field_id,
  26. }
  27. }
  28. }
  29. impl std::convert::From<CalendarLayoutSetting> for CalendarLayoutSettingPB {
  30. fn from(params: CalendarLayoutSetting) -> Self {
  31. CalendarLayoutSettingPB {
  32. field_id: params.field_id,
  33. layout_ty: params.layout_ty.into(),
  34. first_day_of_week: params.first_day_of_week,
  35. show_weekends: params.show_weekends,
  36. show_week_numbers: params.show_week_numbers,
  37. }
  38. }
  39. }
  40. #[derive(Debug, Clone, Eq, PartialEq, Default, ProtoBuf_Enum)]
  41. #[repr(u8)]
  42. pub enum CalendarLayoutPB {
  43. #[default]
  44. MonthLayout = 0,
  45. WeekLayout = 1,
  46. DayLayout = 2,
  47. }
  48. impl std::convert::From<CalendarLayoutPB> for CalendarLayout {
  49. fn from(pb: CalendarLayoutPB) -> Self {
  50. match pb {
  51. CalendarLayoutPB::MonthLayout => CalendarLayout::Month,
  52. CalendarLayoutPB::WeekLayout => CalendarLayout::Week,
  53. CalendarLayoutPB::DayLayout => CalendarLayout::Day,
  54. }
  55. }
  56. }
  57. impl std::convert::From<CalendarLayout> for CalendarLayoutPB {
  58. fn from(layout: CalendarLayout) -> Self {
  59. match layout {
  60. CalendarLayout::Month => CalendarLayoutPB::MonthLayout,
  61. CalendarLayout::Week => CalendarLayoutPB::WeekLayout,
  62. CalendarLayout::Day => CalendarLayoutPB::DayLayout,
  63. }
  64. }
  65. }
  66. #[derive(Debug, Clone, Default, ProtoBuf)]
  67. pub struct CalendarEventRequestPB {
  68. #[pb(index = 1)]
  69. pub view_id: String,
  70. // Currently, requesting the events within the specified month
  71. // is not supported
  72. #[pb(index = 2)]
  73. pub month: String,
  74. }
  75. #[derive(Debug, Clone, Default)]
  76. pub struct CalendarEventRequestParams {
  77. pub view_id: String,
  78. pub month: String,
  79. }
  80. impl TryInto<CalendarEventRequestParams> for CalendarEventRequestPB {
  81. type Error = ErrorCode;
  82. fn try_into(self) -> Result<CalendarEventRequestParams, Self::Error> {
  83. let view_id = NotEmptyStr::parse(self.view_id).map_err(|_| ErrorCode::ViewIdIsInvalid)?;
  84. Ok(CalendarEventRequestParams {
  85. view_id: view_id.0,
  86. month: self.month,
  87. })
  88. }
  89. }
  90. #[derive(Debug, Clone, Default, ProtoBuf)]
  91. pub struct CalendarEventPB {
  92. #[pb(index = 1)]
  93. pub row_id: String,
  94. #[pb(index = 2)]
  95. pub date_field_id: String,
  96. #[pb(index = 3)]
  97. pub title: String,
  98. #[pb(index = 4)]
  99. pub timestamp: i64,
  100. }
  101. #[derive(Debug, Clone, Default, ProtoBuf)]
  102. pub struct RepeatedCalendarEventPB {
  103. #[pb(index = 1)]
  104. pub items: Vec<CalendarEventPB>,
  105. }
  106. #[derive(Debug, Clone, Default, ProtoBuf)]
  107. pub struct MoveCalendarEventPB {
  108. #[pb(index = 1)]
  109. pub row_id: String,
  110. #[pb(index = 2)]
  111. pub field_id: String,
  112. #[pb(index = 3)]
  113. pub timestamp: i64,
  114. }