From 3dce9b075e665e50baafae2f53522ac43701ba2c Mon Sep 17 00:00:00 2001 From: Brett Spradling Date: Sat, 4 Dec 2021 12:08:52 -0800 Subject: [PATCH] wip --- src/ids.rs | 18 ++++++++++++------ src/lib.rs | 8 +++++--- src/models/properties.rs | 4 ++-- src/models/search.rs | 18 +++++++++++++++--- 4 files changed, 34 insertions(+), 14 deletions(-) diff --git a/src/ids.rs b/src/ids.rs index 2ede5e0..5e374ba 100644 --- a/src/ids.rs +++ b/src/ids.rs @@ -28,12 +28,18 @@ where } } -macro_rules! identifer { +macro_rules! identifier { ($name:ident) => { #[derive(serde::Serialize, serde::Deserialize, Debug, Eq, PartialEq, Hash, Clone)] #[serde(transparent)] pub struct $name(String); + impl $name { + pub fn new(value: String) -> Self { + $name(value) + } + } + impl Identifier for $name { fn value(&self) -> &str { &self.0 @@ -48,11 +54,11 @@ macro_rules! identifer { }; } -identifer!(DatabaseId); -identifer!(PageId); -identifer!(BlockId); -identifer!(UserId); -identifer!(PropertyId); +identifier!(DatabaseId); +identifier!(PageId); +identifier!(BlockId); +identifier!(UserId); +identifier!(PropertyId); impl From for BlockId { fn from(page_id: PageId) -> Self { diff --git a/src/lib.rs b/src/lib.rs index 98ea97f..cbd60cb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,6 @@ use crate::ids::{BlockId, DatabaseId}; use crate::models::error::ErrorResponse; -use crate::models::search::{DatabaseQuery, SearchRequest}; +use crate::models::search::{DatabaseQuery, SearchRequest, Foo}; use crate::models::{Block, Database, ListResponse, Object, Page}; use ids::AsIdentifier; use reqwest::header::{HeaderMap, HeaderValue}; @@ -10,6 +10,7 @@ use tracing::Instrument; pub mod ids; pub mod models; pub use chrono; +use serde::Serialize; #[cfg(test)] mod tests; @@ -162,13 +163,14 @@ impl NotionApi { } /// Query a database and return the matching pages. - pub async fn query_database( + pub async fn query_database( &self, database: D, query: T, ) -> Result, Error> where - T: Into, + F: Foo + Serialize, + T: Into>, D: AsIdentifier, { let result = self diff --git a/src/models/properties.rs b/src/models/properties.rs index b46b7f7..541f74c 100644 --- a/src/models/properties.rs +++ b/src/models/properties.rs @@ -286,7 +286,7 @@ pub enum PropertyValue { /// Relation { id: PropertyId, - relation: RelationValue, + relation: Vec, }, Rollup { id: PropertyId, @@ -306,7 +306,7 @@ pub enum PropertyValue { }, Url { id: PropertyId, - url: String, + url: Option, }, Email { id: PropertyId, diff --git a/src/models/search.rs b/src/models/search.rs index e7d8189..e95c5a6 100644 --- a/src/models/search.rs +++ b/src/models/search.rs @@ -263,6 +263,15 @@ pub enum PropertyCondition { And(Vec), } +pub trait Foo {} + +#[derive(Serialize, Debug, Eq, PartialEq, Clone)] +#[serde(rename_all = "lowercase")] +pub enum CompoundFilter { + And(Vec), + Or(Vec), +} + #[derive(Serialize, Debug, Eq, PartialEq, Clone)] pub struct FilterCondition { pub property: String, @@ -270,6 +279,9 @@ pub struct FilterCondition { pub condition: PropertyCondition, } +impl Foo for CompoundFilter{} +impl Foo for FilterCondition{} + #[derive(Serialize, Debug, Eq, PartialEq, Hash, Copy, Clone)] #[serde(rename_all = "snake_case")] pub enum DatabaseSortTimestamp { @@ -291,16 +303,16 @@ pub struct DatabaseSort { } #[derive(Serialize, Debug, Eq, PartialEq, Default, Clone)] -pub struct DatabaseQuery { +pub struct DatabaseQuery { #[serde(skip_serializing_if = "Option::is_none")] pub sorts: Option>, #[serde(skip_serializing_if = "Option::is_none")] - pub filter: Option, + pub filter: Option, #[serde(flatten)] pub paging: Option, } -impl Pageable for DatabaseQuery { +impl Pageable for DatabaseQuery { fn start_from(self, starting_point: Option) -> Self { DatabaseQuery { paging: Some(Paging {