From bb6c77004f07281a051f79e8b1f650b0f0e9279a Mon Sep 17 00:00:00 2001 From: PARK BYUNG JUN Date: Mon, 8 Aug 2022 09:28:25 +0000 Subject: [PATCH] convert is added --- src/models/pagination/mod.rs | 44 +++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) 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, + } + } +}