ext.rs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. use crate::errors::SyncError;
  2. use crate::RevisionSyncPersistence;
  3. use document_model::document::DocumentInfo;
  4. use folder_model::FolderInfo;
  5. use lib_infra::future::BoxResultFuture;
  6. use revision_model::Revision;
  7. use std::fmt::Debug;
  8. use std::sync::Arc;
  9. pub trait FolderCloudPersistence: Send + Sync + Debug {
  10. fn read_folder(&self, user_id: &str, folder_id: &str) -> BoxResultFuture<FolderInfo, SyncError>;
  11. fn create_folder(
  12. &self,
  13. user_id: &str,
  14. folder_id: &str,
  15. revisions: Vec<Revision>,
  16. ) -> BoxResultFuture<Option<FolderInfo>, SyncError>;
  17. fn save_folder_revisions(&self, revisions: Vec<Revision>) -> BoxResultFuture<(), SyncError>;
  18. fn read_folder_revisions(
  19. &self,
  20. folder_id: &str,
  21. rev_ids: Option<Vec<i64>>,
  22. ) -> BoxResultFuture<Vec<Revision>, SyncError>;
  23. fn reset_folder(
  24. &self,
  25. folder_id: &str,
  26. revisions: Vec<Revision>,
  27. ) -> BoxResultFuture<(), SyncError>;
  28. }
  29. impl RevisionSyncPersistence for Arc<dyn FolderCloudPersistence> {
  30. fn read_revisions(
  31. &self,
  32. object_id: &str,
  33. rev_ids: Option<Vec<i64>>,
  34. ) -> BoxResultFuture<Vec<Revision>, SyncError> {
  35. (**self).read_folder_revisions(object_id, rev_ids)
  36. }
  37. fn save_revisions(&self, revisions: Vec<Revision>) -> BoxResultFuture<(), SyncError> {
  38. (**self).save_folder_revisions(revisions)
  39. }
  40. fn reset_object(
  41. &self,
  42. object_id: &str,
  43. revisions: Vec<Revision>,
  44. ) -> BoxResultFuture<(), SyncError> {
  45. (**self).reset_folder(object_id, revisions)
  46. }
  47. }
  48. pub trait DocumentCloudPersistence: Send + Sync + Debug {
  49. fn read_document(&self, doc_id: &str) -> BoxResultFuture<DocumentInfo, SyncError>;
  50. fn create_document(
  51. &self,
  52. doc_id: &str,
  53. revisions: Vec<Revision>,
  54. ) -> BoxResultFuture<Option<DocumentInfo>, SyncError>;
  55. fn read_document_revisions(
  56. &self,
  57. doc_id: &str,
  58. rev_ids: Option<Vec<i64>>,
  59. ) -> BoxResultFuture<Vec<Revision>, SyncError>;
  60. fn save_document_revisions(&self, revisions: Vec<Revision>) -> BoxResultFuture<(), SyncError>;
  61. fn reset_document(
  62. &self,
  63. doc_id: &str,
  64. revisions: Vec<Revision>,
  65. ) -> BoxResultFuture<(), SyncError>;
  66. }
  67. impl RevisionSyncPersistence for Arc<dyn DocumentCloudPersistence> {
  68. fn read_revisions(
  69. &self,
  70. object_id: &str,
  71. rev_ids: Option<Vec<i64>>,
  72. ) -> BoxResultFuture<Vec<Revision>, SyncError> {
  73. (**self).read_document_revisions(object_id, rev_ids)
  74. }
  75. fn save_revisions(&self, revisions: Vec<Revision>) -> BoxResultFuture<(), SyncError> {
  76. (**self).save_document_revisions(revisions)
  77. }
  78. fn reset_object(
  79. &self,
  80. object_id: &str,
  81. revisions: Vec<Revision>,
  82. ) -> BoxResultFuture<(), SyncError> {
  83. (**self).reset_document(object_id, revisions)
  84. }
  85. }