diff options
author | 2021-05-15 10:01:03 -0700 | |
---|---|---|
committer | 2021-05-15 10:01:03 -0700 | |
commit | 371a3e49ffe52c2684030f4d3cb669a3aac2b3ca (patch) | |
tree | 8d624c21a3faf2cf437a89b1102d7be25fa28fea /src/models | |
parent | d18843ab949e803e25c48f514b4e25244477c731 (diff) | |
download | notion-371a3e49ffe52c2684030f4d3cb669a3aac2b3ca.tar.gz notion-371a3e49ffe52c2684030f4d3cb669a3aac2b3ca.tar.zst notion-371a3e49ffe52c2684030f4d3cb669a3aac2b3ca.zip |
adding basic property filters
Diffstat (limited to 'src/models')
-rw-r--r-- | src/models/search.rs | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/src/models/search.rs b/src/models/search.rs index ee0bb51..09a74b4 100644 --- a/src/models/search.rs +++ b/src/models/search.rs @@ -51,6 +51,42 @@ pub struct SearchRequest { paging: Option<Paging>, } +#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)] +#[serde(rename_all = "snake_case")] +pub enum TextCondition { + Equals(String), + DoesNotEqual(String), + Contains(String), + DoesNotContain(String), + StartsWith(String), + EndsWith(String), + IsEmpty, + IsNotEmpty, +} + +#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)] +#[serde(rename_all = "lowercase")] +pub enum PropertyCondition { + Text(TextCondition), +} + +#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)] +pub struct FilterCondition { + property: String, + #[serde(flatten)] + condition: PropertyCondition, +} + +#[derive(Serialize, Debug, Eq, PartialEq, Default)] +pub struct DatabaseQuery { + #[serde(skip_serializing_if = "Option::is_none")] + sorts: Option<Sort>, + #[serde(skip_serializing_if = "Option::is_none")] + filter: Option<FilterCondition>, + #[serde(flatten)] + paging: Option<Paging>, +} + #[derive(Debug, Eq, PartialEq)] pub enum NotionSearch { Query(String), @@ -88,3 +124,25 @@ impl From<NotionSearch> for SearchRequest { } } } + +#[cfg(test)] +mod tests { + mod text_filters { + use crate::models::search::PropertyCondition::Text; + use crate::models::search::{FilterCondition, PropertyCondition, TextCondition}; + + #[test] + fn text_property_equals() -> Result<(), Box<dyn std::error::Error>> { + let json = serde_json::to_string(&FilterCondition { + property: "Name".to_string(), + condition: Text(TextCondition::Equals("Test".to_string())), + })?; + assert_eq!( + dbg!(json), + r#"{"property":"Name","text":{"equals":"Test"}}"# + ); + + Ok(()) + } + } +} |