entities.rs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. use crate::errors::ErrorCode;
  2. use flowy_derive::{ProtoBuf, ProtoBuf_Enum};
  3. use std::convert::TryInto;
  4. #[derive(PartialEq, Debug, ProtoBuf_Enum, Clone)]
  5. pub enum ExportType {
  6. Text = 0,
  7. Markdown = 1,
  8. Link = 2,
  9. }
  10. impl std::default::Default for ExportType {
  11. fn default() -> Self {
  12. ExportType::Text
  13. }
  14. }
  15. impl std::convert::From<i32> for ExportType {
  16. fn from(val: i32) -> Self {
  17. match val {
  18. 0 => ExportType::Text,
  19. 1 => ExportType::Markdown,
  20. 2 => ExportType::Link,
  21. _ => {
  22. log::error!("Invalid export type: {}", val);
  23. ExportType::Text
  24. }
  25. }
  26. }
  27. }
  28. #[derive(Default, ProtoBuf)]
  29. pub struct ExportPayloadPB {
  30. #[pb(index = 1)]
  31. pub view_id: String,
  32. #[pb(index = 2)]
  33. pub export_type: ExportType,
  34. }
  35. #[derive(Default, Debug)]
  36. pub struct ExportParams {
  37. pub view_id: String,
  38. pub export_type: ExportType,
  39. }
  40. impl TryInto<ExportParams> for ExportPayloadPB {
  41. type Error = ErrorCode;
  42. fn try_into(self) -> Result<ExportParams, Self::Error> {
  43. Ok(ExportParams {
  44. view_id: self.view_id,
  45. export_type: self.export_type,
  46. })
  47. }
  48. }
  49. #[derive(Default, ProtoBuf)]
  50. pub struct ExportDataPB {
  51. #[pb(index = 1)]
  52. pub data: String,
  53. #[pb(index = 2)]
  54. pub export_type: ExportType,
  55. }