feat: added pagination and get_title helper method

This commit is contained in:
Bram Dingelstad 2023-07-09 21:57:59 +02:00
parent a1fe4ae68c
commit 3ae1313b79

View file

@ -344,6 +344,20 @@ impl Databases {
json
};
let json = if let Some(cursor) = options.start_cursor {
if let Some(mut json) = json {
json.as_object_mut()
.expect("Some object to be editable")
.insert("start_cursor".to_string(), Value::String(cursor));
Some(json)
} else {
Some(json!({ "start_cursor": cursor }))
}
} else {
json
};
if let Some(json) = json {
request = request.json(&json);
}
@ -408,6 +422,7 @@ pub struct DatabaseQueryOptions<'a> {
// TODO: Implement spec for filter?
pub filter: Option<Value>,
pub sorts: Option<Value>,
pub start_cursor: Option<String>,
}
#[derive(Clone)]
@ -967,6 +982,18 @@ impl Page {
&& property.id().expect("id that is_some() to be unwrappable") == id
})
}
pub fn get_title(&self) -> &Vec<RichText> {
if let Property::Title { title, .. } = self
.get_property_by_id("title")
.expect("every page to have a title")
.1
{
title
} else {
unreachable!("Expected title to be of type title")
}
}
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]