diff --git a/src/lib.rs b/src/lib.rs index 0c2ed0a..a20b378 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -276,6 +276,7 @@ pub struct Databases<'a> { } impl Databases<'_> { + // FIXME: This call can have Databases mixed in with the Page's, needs an intermediary pub async fn query<'a>( &self, options: DatabaseQueryOptions<'a>, @@ -824,6 +825,7 @@ pub enum DatabaseProperty { Status { id: String, name: String, + // TODO: add "groups" options: DatabaseSelectOptions, }, Title { @@ -919,7 +921,7 @@ where serde_json::from_value::(value.to_owned()).unwrap_or_else(|error| { log::warn!( - "Could not parse value because of error, defaulting to DatabaseProperty::Unsupported:\n= ERROR:\n{error:?}\n= JSON:\n{:?}\n---", + "Could not parse DatabaseProperty value because of error, defaulting to DatabaseProperty::Unsupported:\n= ERROR:\n{error:?}\n= JSON:\n{:?}\n---", serde_json::to_string_pretty(&value).expect("to pretty print the database property error") ); DatabaseProperty::Unsupported(value.to_owned()) @@ -935,6 +937,7 @@ pub struct Number { } #[derive(Debug, Serialize, Deserialize, Clone, PartialEq)] +#[serde(rename_all = "snake_case")] pub enum NumberFormat { ArgentinePeso, Baht, @@ -992,6 +995,22 @@ pub struct Relation { } #[derive(Debug, Serialize, Deserialize, Clone, PartialEq)] +#[serde(tag = "type")] +#[serde(rename_all = "snake_case")] +// TODO: Implement all enums here +pub enum Rollup { + Array { + function: RollupFunction, + array: Vec, + }, + Date, + Incomplete, + Number, + Unsupported, +} + +#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)] +#[serde(rename_all = "snake_case")] pub enum RollupFunction { Average, Checked, @@ -1020,12 +1039,73 @@ pub enum RollupFunction { } #[derive(Debug, Serialize, Deserialize, Clone, PartialEq)] -pub enum RollupValue { - Array, - Date, - Incomplete, - Number, - Unsupported, +#[serde(tag = "type")] +#[serde(rename_all = "snake_case")] +pub enum RollupProperty { + Checkbox { + checkbox: bool, + }, + CreatedBy {}, + CreatedTime { + created_time: DateValue, + }, + Date { + date: Option, + }, + Email { + email: Option, + }, + Files { + files: Vec, + }, + Formula { + name: Option, + formula: Formula, + }, + LastEditedBy { + last_edited_by: User, + }, + LastEditedTime { + last_edited_time: DateValue, + }, + Select { + select: SelectOption, + }, + MultiSelect { + multi_select: Vec, + }, + Number { + number: Option, + }, + People {}, + PhoneNumber {}, + Relation { + relation: Vec, + }, + Rollup { + rollup: Rollup, + }, + RichText { + rich_text: Vec, + }, + Status { + status: Option, + }, + Title { + title: Vec, + }, + Url { + url: Option, + }, + Verification { + state: VerificationState, + verified_by: Option, + date: Option, + }, + UniqueId {}, + Button {}, + + Unsupported(Value), } // TODO: Paginate all possible responses @@ -1034,6 +1114,7 @@ pub struct QueryResponse { pub has_more: Option, pub next_cursor: Option, pub results: Vec, + pub page_or_database: Value, } #[derive(Debug, Serialize, Deserialize, Clone, PartialEq)] @@ -1087,6 +1168,7 @@ pub enum Property { }, CreatedBy { id: String, + created_by: User, }, CreatedTime { id: String, @@ -1131,9 +1213,11 @@ pub enum Property { }, People { id: String, + people: Vec, }, PhoneNumber { id: String, + phone_number: Option, }, Relation { id: String, @@ -1142,9 +1226,7 @@ pub enum Property { }, Rollup { id: String, - function: RollupFunction, - // TODO: This will not parse properly and needs custom deserializer code - value: RollupValue, + rollup: Rollup, }, RichText { id: String, @@ -1152,7 +1234,7 @@ pub enum Property { }, Status { id: String, - status: SelectOption, + status: Option, }, Title { id: String, @@ -1164,12 +1246,11 @@ pub enum Property { }, Verification { id: String, - state: VerificationState, - verified_by: Option, - date: Option, + verification: Verification, }, UniqueId { id: String, + unique_id: UniqueId, }, Button { id: String, @@ -1280,7 +1361,7 @@ where key.to_owned(), serde_json::from_value::(value.to_owned()).unwrap_or_else(|error| { log::warn!( - "Could not parse value because of error, defaulting to Property::Unsupported:\n= ERROR:\n{error:#?}\n= JSON:\n{}\n---", + "Could not parse Property value because of error, defaulting to Property::Unsupported:\n= ERROR:\n{error:#?}\n= JSON:\n{}\n---", serde_json::to_string_pretty(&value).expect("to pretty print Property errors") ); Property::Unsupported(value.to_owned()) @@ -1289,10 +1370,26 @@ where }) .collect::>()) } + #[derive(Debug, Serialize, Deserialize, Clone, PartialEq)] +#[serde(rename_all = "snake_case")] pub enum VerificationState { Verified, Unverified, + Expired, +} + +#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)] +pub struct Verification { + state: VerificationState, + verified_by: Option, + date: Option, +} + +#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)] +pub struct UniqueId { + number: i32, + prefix: Option, } #[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]