feat: added more types and fixed broken ones
This commit is contained in:
parent
5df6d0f7d9
commit
43e5fc6005
1 changed files with 112 additions and 15 deletions
127
src/lib.rs
127
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::<DatabaseProperty>(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<RollupProperty>,
|
||||
},
|
||||
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<Date>,
|
||||
},
|
||||
Email {
|
||||
email: Option<String>,
|
||||
},
|
||||
Files {
|
||||
files: Vec<File>,
|
||||
},
|
||||
Formula {
|
||||
name: Option<String>,
|
||||
formula: Formula,
|
||||
},
|
||||
LastEditedBy {
|
||||
last_edited_by: User,
|
||||
},
|
||||
LastEditedTime {
|
||||
last_edited_time: DateValue,
|
||||
},
|
||||
Select {
|
||||
select: SelectOption,
|
||||
},
|
||||
MultiSelect {
|
||||
multi_select: Vec<SelectOption>,
|
||||
},
|
||||
Number {
|
||||
number: Option<f32>,
|
||||
},
|
||||
People {},
|
||||
PhoneNumber {},
|
||||
Relation {
|
||||
relation: Vec<Relation>,
|
||||
},
|
||||
Rollup {
|
||||
rollup: Rollup,
|
||||
},
|
||||
RichText {
|
||||
rich_text: Vec<RichText>,
|
||||
},
|
||||
Status {
|
||||
status: Option<SelectOption>,
|
||||
},
|
||||
Title {
|
||||
title: Vec<RichText>,
|
||||
},
|
||||
Url {
|
||||
url: Option<String>,
|
||||
},
|
||||
Verification {
|
||||
state: VerificationState,
|
||||
verified_by: Option<User>,
|
||||
date: Option<Date>,
|
||||
},
|
||||
UniqueId {},
|
||||
Button {},
|
||||
|
||||
Unsupported(Value),
|
||||
}
|
||||
|
||||
// TODO: Paginate all possible responses
|
||||
|
|
@ -1034,6 +1114,7 @@ pub struct QueryResponse<T> {
|
|||
pub has_more: Option<bool>,
|
||||
pub next_cursor: Option<String>,
|
||||
pub results: Vec<T>,
|
||||
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<User>,
|
||||
},
|
||||
PhoneNumber {
|
||||
id: String,
|
||||
phone_number: Option<String>,
|
||||
},
|
||||
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<SelectOption>,
|
||||
},
|
||||
Title {
|
||||
id: String,
|
||||
|
|
@ -1164,12 +1246,11 @@ pub enum Property {
|
|||
},
|
||||
Verification {
|
||||
id: String,
|
||||
state: VerificationState,
|
||||
verified_by: Option<User>,
|
||||
date: Option<Date>,
|
||||
verification: Verification,
|
||||
},
|
||||
UniqueId {
|
||||
id: String,
|
||||
unique_id: UniqueId,
|
||||
},
|
||||
Button {
|
||||
id: String,
|
||||
|
|
@ -1280,7 +1361,7 @@ where
|
|||
key.to_owned(),
|
||||
serde_json::from_value::<Property>(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::<HashMap<String, Property>>())
|
||||
}
|
||||
|
||||
#[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<User>,
|
||||
date: Option<Date>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
|
||||
pub struct UniqueId {
|
||||
number: i32,
|
||||
prefix: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
|
||||
|
|
|
|||
Loading…
Reference in a new issue