diff options
author | 2021-08-30 08:27:10 -0700 | |
---|---|---|
committer | 2021-08-30 08:27:10 -0700 | |
commit | eab748bf990a304063c476fb7cdeab0ec8c325f7 (patch) | |
tree | 2211af13fff6028e346641aacf3fad2a1fe3c512 /src/models | |
parent | a78a8d9444426a608888755eb1537905b7d1d96a (diff) | |
download | notion-eab748bf990a304063c476fb7cdeab0ec8c325f7.tar.gz notion-eab748bf990a304063c476fb7cdeab0ec8c325f7.tar.zst notion-eab748bf990a304063c476fb7cdeab0ec8c325f7.zip |
Improve ergonomics
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. |