diff options
author | 2021-05-16 09:37:52 -0700 | |
---|---|---|
committer | 2021-05-16 09:37:52 -0700 | |
commit | fa85eb7182471a0fa15b7268e4c9adac326756f8 (patch) | |
tree | bcfec569e6a2015a4eb18dc8824ab20cf771947b /src/models.rs | |
parent | c0f5b2bb6c470dc3669c5cbec53a19133223dc42 (diff) | |
download | notion-fa85eb7182471a0fa15b7268e4c9adac326756f8.tar.gz notion-fa85eb7182471a0fa15b7268e4c9adac326756f8.tar.zst notion-fa85eb7182471a0fa15b7268e4c9adac326756f8.zip |
fix: Fixes issue #3, search can return objects (#5)
Diffstat (limited to 'src/models.rs')
-rw-r--r-- | src/models.rs | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/src/models.rs b/src/models.rs index 2581e13..4051787 100644 --- a/src/models.rs +++ b/src/models.rs @@ -8,13 +8,14 @@ use crate::models::text::RichText; use serde::{Deserialize, Serialize}; use std::collections::HashMap; +use crate::models::paging::PagingCursor; use crate::Identifiable; pub use chrono::{DateTime, Utc}; pub use serde_json::value::Number; use std::fmt::{Display, Formatter}; #[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Copy, Clone)] -#[serde(rename_all = "lowercase")] +#[serde(rename_all = "snake_case")] enum ObjectType { Database, List, @@ -77,9 +78,9 @@ impl Identifiable for Database { #[derive(Serialize, Deserialize, Eq, PartialEq, Debug, Clone)] pub struct ListResponse<T> { - results: Vec<T>, - next_cursor: Option<String>, - has_more: bool, + pub results: Vec<T>, + pub next_cursor: Option<PagingCursor>, + pub has_more: bool, } impl<T> ListResponse<T> { @@ -136,17 +137,33 @@ pub struct Page { #[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)] pub struct Block {} -#[derive(Serialize, Deserialize, Clone)] +#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq)] #[serde(tag = "object")] +#[serde(rename_all = "snake_case")] pub enum Object { Database { #[serde(flatten)] database: Database, }, - Page {}, + Page { + #[serde(flatten)] + page: Page, + }, List { + #[serde(flatten)] list: ListResponse<Object>, }, + User { + #[serde(flatten)] + user: User, + }, + Block {}, +} + +impl Object { + pub fn is_database(&self) -> bool { + matches!(self, Object::Database { .. }) + } } /// A zero-cost wrapper type around a Page ID |