From 8a6ee9bca902db076be12745967a69c7c184e044 Mon Sep 17 00:00:00 2001 From: Jake Swenson Date: Fri, 14 May 2021 07:33:45 -0700 Subject: split models --- src/models/properties.rs | 84 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 src/models/properties.rs (limited to 'src/models/properties.rs') diff --git a/src/models/properties.rs b/src/models/properties.rs new file mode 100644 index 0000000..cc59907 --- /dev/null +++ b/src/models/properties.rs @@ -0,0 +1,84 @@ +use serde::{Deserialize, Serialize}; + +#[derive(Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)] +#[serde(transparent)] +pub struct PropertyId(String); + +/// How the number is displayed in Notion. +#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)] +#[serde(tag = "type")] +#[serde(rename_all = "snake_case")] +pub enum NumberFormat { + Number, + NumberWithCommas, + Percent, + Dollar, + Euro, + Pound, + Yen, + Ruble, + Rupee, + Won, + Yuan, +} + +#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)] +#[serde(transparent)] +pub struct SelectOptionId(String); + +#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)] +#[serde(rename_all = "lowercase")] +pub enum Color { + Default, + Gray, + Brown, + Orange, + Yellow, + Green, + Blue, + Purple, + Pink, + Red, +} + +#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)] +pub struct SelectOption { + name: String, + id: SelectOptionId, + color: Color, +} + +#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)] +pub struct Select { + /// Sorted list of options available for this property. + options: Vec, +} + +#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)] +#[serde(tag = "type")] +#[serde(rename_all = "snake_case")] +pub enum PropertyConfiguration { + /// Represents the special Title property required on every database. + /// See https://developers.notion.com/reference/database#title-configuration + Title { id: PropertyId }, + /// Represents a Text property + /// https://developers.notion.com/reference/database#text-configuration + #[serde(rename = "rich_text")] + Text { id: PropertyId }, + /// Represents a Number Property + /// See https://developers.notion.com/reference/database#number-configuration + Number { + id: PropertyId, + /// How the number is displayed in Notion. + format: NumberFormat, + }, + /// Represents a Select Property + /// See https://developers.notion.com/reference/database#select-configuration + Select { id: PropertyId, select: Select }, + /// Represents a Date Property + /// See https://developers.notion.com/reference/database#date-configuration + Date { id: PropertyId }, + /// Represents a File Property + /// See https://developers.notion.com/reference/database#date-configuration + File { id: PropertyId }, +} -- cgit v1.2.3