diff --git a/src/models/pagination/mod.rs b/src/models/pagination/mod.rs index d013da3..04209da 100644 --- a/src/models/pagination/mod.rs +++ b/src/models/pagination/mod.rs @@ -1,6 +1,6 @@ //! //! - +use beteran_protobuf_rust as bpr; /// #[derive(Debug, Clone)] pub enum Sort { @@ -10,6 +10,30 @@ pub enum Sort { DESC(String), } +impl From for bpr::protobuf::pagination::Sort { + fn from(d: Sort) -> Self { + match d { + Sort::ASC(by) => bpr::protobuf::pagination::Sort { + by, + order: bpr::protobuf::pagination::SortOrder::Asc as i32, + }, + Sort::DESC(by) => bpr::protobuf::pagination::Sort { + by, + order: bpr::protobuf::pagination::SortOrder::Desc as i32, + }, + } + } +} + +impl From for Sort { + fn from(d: bpr::protobuf::pagination::Sort) -> Self { + match d.order { + x if x == bpr::protobuf::pagination::SortOrder::Desc as i32 => Sort::DESC(d.by), + _ => Sort::ASC(d.by), + } + } +} + /// #[derive(Debug, Clone)] pub struct Pagination { @@ -18,3 +42,21 @@ pub struct Pagination { /// pub page_size: Option, } + +impl From for bpr::protobuf::pagination::Pagination { + fn from(d: Pagination) -> Self { + bpr::protobuf::pagination::Pagination { + page: d.page, + page_size: d.page_size, + } + } +} + +impl From for Pagination { + fn from(d: bpr::protobuf::pagination::Pagination) -> Self { + Pagination { + page: d.page, + page_size: d.page_size, + } + } +}