From 5ebc1f11e3f7016cf316cf240076cea3402a09e0 Mon Sep 17 00:00:00 2001 From: Ivy Pierlot Date: Mon, 12 Aug 2024 11:22:23 +1000 Subject: [PATCH] add new props --- src/models/mod.rs | 22 +++++++- 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, pub properties: HashMap, } +#[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 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, 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 - Title { id: PropertyId }, + Title { + id: PropertyId, + }, /// Represents a Text property /// #[serde(rename = "rich_text")] - Text { id: PropertyId }, + Text { + id: PropertyId, + }, /// Represents a Number Property /// See Number { @@ -170,9 +174,15 @@ pub enum PropertyConfiguration { }, /// Represents a Select Property /// See - 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 MultiSelect { @@ -181,41 +191,78 @@ pub enum PropertyConfiguration { }, /// Represents a Date Property /// See - Date { id: PropertyId }, + Date { + id: PropertyId, + }, /// Represents a People Property /// See - People { id: PropertyId }, + People { + id: PropertyId, + }, /// Represents a File Property /// See // 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 - Checkbox { id: PropertyId }, + Checkbox { + id: PropertyId, + }, /// Represents a URL Property /// See - Url { id: PropertyId }, + Url { + id: PropertyId, + }, /// Represents a Email Property /// See - Email { id: PropertyId }, + Email { + id: PropertyId, + }, /// Represents a Phone number Property /// See - PhoneNumber { id: PropertyId }, + PhoneNumber { + id: PropertyId, + }, /// See - Formula { id: PropertyId, formula: Formula }, + Formula { + id: PropertyId, + formula: Formula, + }, /// See - Relation { id: PropertyId, relation: Relation }, + Relation { + id: PropertyId, + relation: Relation, + }, /// See - Rollup { id: PropertyId, rollup: Rollup }, + Rollup { + id: PropertyId, + rollup: Rollup, + }, /// See - CreatedTime { id: PropertyId }, + CreatedTime { + id: PropertyId, + }, /// See - CreatedBy { id: PropertyId }, + CreatedBy { + id: PropertyId, + }, /// See - LastEditedTime { id: PropertyId }, + LastEditedTime { + id: PropertyId, + }, /// See - 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, }, /// - People { id: PropertyId, people: Vec }, + People { + id: PropertyId, + people: Vec, + }, /// Files { id: PropertyId, files: Option>, }, /// - Checkbox { id: PropertyId, checkbox: bool }, + Checkbox { + id: PropertyId, + checkbox: bool, + }, /// - Url { id: PropertyId, url: Option }, + Url { + id: PropertyId, + url: Option, + }, /// Email { id: PropertyId, @@ -359,7 +415,10 @@ pub enum PropertyValue { created_time: DateTime, }, /// - CreatedBy { id: PropertyId, created_by: User }, + CreatedBy { + id: PropertyId, + created_by: User, + }, /// 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, + pub number: u32, } ///