diff options
Diffstat (limited to 'src/models')
-rw-r--r-- | src/models/paging.rs | 6 | ||||
-rw-r--r-- | src/models/search.rs | 13 |
2 files changed, 16 insertions, 3 deletions
diff --git a/src/models/paging.rs b/src/models/paging.rs index 3b97301..481c235 100644 --- a/src/models/paging.rs +++ b/src/models/paging.rs @@ -4,10 +4,14 @@ use serde::{Deserialize, Serialize}; #[serde(transparent)] pub struct PagingCursor(String); -#[derive(Serialize, Debug, Eq, PartialEq, Default)] +#[derive(Serialize, Debug, Eq, PartialEq, Default, Clone)] pub struct Paging { #[serde(skip_serializing_if = "Option::is_none")] pub start_cursor: Option<PagingCursor>, #[serde(skip_serializing_if = "Option::is_none")] pub page_size: Option<u8>, } + +pub trait Pageable { + fn start_from(self, starting_point: Paging) -> Self; +} diff --git a/src/models/search.rs b/src/models/search.rs index 3e5d782..22dab76 100644 --- a/src/models/search.rs +++ b/src/models/search.rs @@ -1,5 +1,5 @@ use crate::ids::{PageId, UserId}; -use crate::models::paging::Paging; +use crate::models::paging::{Pageable, Paging}; use crate::models::Number; use chrono::{DateTime, Utc}; use serde::ser::SerializeMap; @@ -290,7 +290,7 @@ pub struct DatabaseSort { pub direction: SortDirection, } -#[derive(Serialize, Debug, Eq, PartialEq, Default)] +#[derive(Serialize, Debug, Eq, PartialEq, Default, Clone)] pub struct DatabaseQuery { #[serde(skip_serializing_if = "Option::is_none")] pub sorts: Option<Vec<DatabaseSort>>, @@ -300,6 +300,15 @@ pub struct DatabaseQuery { pub paging: Option<Paging>, } +impl Pageable for DatabaseQuery { + fn start_from(self, starting_point: Paging) -> Self { + DatabaseQuery { + paging: Some(starting_point), + ..self + } + } +} + #[derive(Debug, Eq, PartialEq)] pub enum NotionSearch { /// When supplied, limits which pages are returned by comparing the query to the page title. |