diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/models/mod.rs | 22 | ||||
-rw-r--r-- | src/models/properties.rs | 116 |
2 files changed, 115 insertions, 23 deletions
diff --git a/src/models/mod.rs b/src/models/mod.rs index 795accd..be920fe 100644 --- a/src/models/mod.rs +++ b/src/models/mod.rs @@ -11,11 +11,13 @@ pub mod users; use crate::models::properties::{PropertyConfiguration, PropertyValue}; use crate::models::text::RichText; use crate::Error; +use block::ExternalFileObject; use serde::{Deserialize, Serialize}; +use serde_json::Value; use std::collections::HashMap; use crate::ids::{AsIdentifier, DatabaseId, PageId}; -use crate::models::block::{Block, CreateBlock}; +use crate::models::block::{Block, CreateBlock, FileObject}; use crate::models::error::ErrorResponse; use crate::models::paging::PagingCursor; use crate::models::users::User; @@ -48,9 +50,26 @@ pub struct Database { // // value object // A Property object. + pub icon: Option<IconObject>, pub properties: HashMap<String, PropertyConfiguration>, } +#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)] +#[serde(tag = "type")] +#[serde(rename_all = "snake_case")] +pub enum IconObject { + File { + #[serde(flatten)] + file: FileObject, + }, + External { + external: ExternalFileObject, + }, + Emoji { + emoji: String, + }, +} + impl AsIdentifier<DatabaseId> for Database { fn as_id(&self) -> &DatabaseId { &self.id @@ -200,6 +219,7 @@ pub struct Page { /// The archived status of the page. pub archived: bool, pub properties: Properties, + pub icon: Option<IconObject>, pub parent: Parent, } diff --git a/src/models/properties.rs b/src/models/properties.rs index 918eed6..545a611 100644 --- a/src/models/properties.rs +++ b/src/models/properties.rs @@ -156,11 +156,15 @@ pub struct Rollup { pub enum PropertyConfiguration { /// Represents the special Title property required on every database. /// See <https://developers.notion.com/reference/database#title-configuration> - Title { id: PropertyId }, + Title { + id: PropertyId, + }, /// Represents a Text property /// <https://developers.notion.com/reference/database#text-configuration> #[serde(rename = "rich_text")] - Text { id: PropertyId }, + Text { + id: PropertyId, + }, /// Represents a Number Property /// See <https://developers.notion.com/reference/database#number-configuration> Number { @@ -170,9 +174,15 @@ pub enum PropertyConfiguration { }, /// Represents a Select Property /// See <https://developers.notion.com/reference/database#select-configuration> - Select { id: PropertyId, select: Select }, + Select { + id: PropertyId, + select: Select, + }, /// Represents a Status property - Status { id: PropertyId, status: Status }, + Status { + id: PropertyId, + status: Status, + }, /// Represents a Multi-select Property /// See <https://developers.notion.com/reference/database#multi-select-configuration> MultiSelect { @@ -181,41 +191,78 @@ pub enum PropertyConfiguration { }, /// Represents a Date Property /// See <https://developers.notion.com/reference/database#date-configuration> - Date { id: PropertyId }, + Date { + id: PropertyId, + }, /// Represents a People Property /// See <https://developers.notion.com/reference/database#people-configuration> - People { id: PropertyId }, + People { + id: PropertyId, + }, /// Represents a File Property /// See <https://developers.notion.com/reference/database#file-configuration> // Todo: File a bug with notion // Documentation issue: docs claim type name is `file` but it is in fact `files` - Files { id: PropertyId }, + Files { + id: PropertyId, + }, /// Represents a Checkbox Property /// See <https://developers.notion.com/reference/database#checkbox-configuration> - Checkbox { id: PropertyId }, + Checkbox { + id: PropertyId, + }, /// Represents a URL Property /// See <https://developers.notion.com/reference/database#url-configuration> - Url { id: PropertyId }, + Url { + id: PropertyId, + }, /// Represents a Email Property /// See <https://developers.notion.com/reference/database#email-configuration> - Email { id: PropertyId }, + Email { + id: PropertyId, + }, /// Represents a Phone number Property /// See <https://developers.notion.com/reference/database#phone-number-configuration> - PhoneNumber { id: PropertyId }, + PhoneNumber { + id: PropertyId, + }, /// See <https://developers.notion.com/reference/database#formula-configuration> - Formula { id: PropertyId, formula: Formula }, + Formula { + id: PropertyId, + formula: Formula, + }, /// See <https://developers.notion.com/reference/database#relation-configuration> - Relation { id: PropertyId, relation: Relation }, + Relation { + id: PropertyId, + relation: Relation, + }, /// See <https://developers.notion.com/reference/database#rollup-configuration> - Rollup { id: PropertyId, rollup: Rollup }, + Rollup { + id: PropertyId, + rollup: Rollup, + }, /// See <https://developers.notion.com/reference/database#created-time-configuration> - CreatedTime { id: PropertyId }, + CreatedTime { + id: PropertyId, + }, /// See <https://developers.notion.com/reference/database#created-by-configuration> - CreatedBy { id: PropertyId }, + CreatedBy { + id: PropertyId, + }, /// See <https://developers.notion.com/reference/database#last-edited-time-configuration> - LastEditedTime { id: PropertyId }, + LastEditedTime { + id: PropertyId, + }, /// See <https://developers.notion.com/reference/database#last-edited-by-configuration> - LastEditBy { id: PropertyId }, + LastEditBy { + id: PropertyId, + }, + UniqueId { + id: PropertyId, + }, + Button { + id: PropertyId, + }, } #[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)] @@ -333,16 +380,25 @@ pub enum PropertyValue { rollup: Option<RollupValue>, }, /// <https://developers.notion.com/reference/property-object#people-configuration> - People { id: PropertyId, people: Vec<User> }, + People { + id: PropertyId, + people: Vec<User>, + }, /// <https://developers.notion.com/reference/property-object#files-configuration> Files { id: PropertyId, files: Option<Vec<FileReference>>, }, /// <https://developers.notion.com/reference/property-object#checkbox-configuration> - Checkbox { id: PropertyId, checkbox: bool }, + Checkbox { + id: PropertyId, + checkbox: bool, + }, /// <https://developers.notion.com/reference/property-object#url-configuration> - Url { id: PropertyId, url: Option<String> }, + Url { + id: PropertyId, + url: Option<String>, + }, /// <https://developers.notion.com/reference/property-object#email-configuration> Email { id: PropertyId, @@ -359,7 +415,10 @@ pub enum PropertyValue { created_time: DateTime<Utc>, }, /// <https://developers.notion.com/reference/property-object#created-by-configuration> - CreatedBy { id: PropertyId, created_by: User }, + CreatedBy { + id: PropertyId, + created_by: User, + }, /// <https://developers.notion.com/reference/property-object#last-edited-time-configuration> LastEditedTime { id: PropertyId, @@ -370,6 +429,19 @@ pub enum PropertyValue { id: PropertyId, last_edited_by: User, }, + UniqueId { + id: PropertyId, + unique_id: UniqueidValue, + }, + Button { + id: PropertyId, + }, +} + +#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] +pub struct UniqueidValue { + pub prefix: Option<String>, + pub number: u32, } /// <https://developers.notion.com/reference/page#rollup-property-value-element> |