Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated the api to be have new features #66

Merged
merged 1 commit into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion src/models/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
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;

Check warning on line 16 in src/models/mod.rs

View workflow job for this annotation

GitHub Actions / build

unused import: `serde_json::Value`

Check warning on line 16 in src/models/mod.rs

View workflow job for this annotation

GitHub Actions / build

unused import: `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;
Expand Down Expand Up @@ -48,9 +50,26 @@
//
// 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
Expand Down Expand Up @@ -200,6 +219,7 @@
/// The archived status of the page.
pub archived: bool,
pub properties: Properties,
pub icon: Option<IconObject>,
pub parent: Parent,
}

Expand Down
116 changes: 94 additions & 22 deletions src/models/properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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)]
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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>
Expand Down
Loading