Skip to content
Draft
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
18 changes: 12 additions & 6 deletions src/ids.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,18 @@ where
}
}

macro_rules! identifer {
macro_rules! identifier {
($name:ident) => {
#[derive(serde::Serialize, serde::Deserialize, Debug, Eq, PartialEq, Hash, Clone)]
#[serde(transparent)]
pub struct $name(String);

impl $name {
pub fn new(value: String) -> Self {
$name(value)
}
}

impl Identifier for $name {
fn value(&self) -> &str {
&self.0
Expand All @@ -48,11 +54,11 @@ macro_rules! identifer {
};
}

identifer!(DatabaseId);
identifer!(PageId);
identifer!(BlockId);
identifer!(UserId);
identifer!(PropertyId);
identifier!(DatabaseId);
identifier!(PageId);
identifier!(BlockId);
identifier!(UserId);
identifier!(PropertyId);

impl From<PageId> for BlockId {
fn from(page_id: PageId) -> Self {
Expand Down
8 changes: 5 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::ids::{BlockId, DatabaseId};
use crate::models::error::ErrorResponse;
use crate::models::search::{DatabaseQuery, SearchRequest};
use crate::models::search::{DatabaseQuery, SearchRequest, Foo};
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems.. interesting.. probaly not a type we want to check in

use crate::models::{Block, Database, ListResponse, Object, Page};
use ids::AsIdentifier;
use reqwest::header::{HeaderMap, HeaderValue};
Expand All @@ -10,6 +10,7 @@ use tracing::Instrument;
pub mod ids;
pub mod models;
pub use chrono;
use serde::Serialize;

#[cfg(test)]
mod tests;
Expand Down Expand Up @@ -162,13 +163,14 @@ impl NotionApi {
}

/// Query a database and return the matching pages.
pub async fn query_database<D, T>(
pub async fn query_database<D, T, F>(
&self,
database: D,
query: T,
) -> Result<ListResponse<Page>, Error>
where
T: Into<DatabaseQuery>,
F: Foo + Serialize,
T: Into<DatabaseQuery<F>>,
D: AsIdentifier<DatabaseId>,
{
let result = self
Expand Down
4 changes: 2 additions & 2 deletions src/models/properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ pub enum PropertyValue {
/// <https://developers.notion.com/reference/page#relation-property-values>
Relation {
id: PropertyId,
relation: RelationValue,
relation: Vec<RelationValue>,
},
Rollup {
id: PropertyId,
Expand All @@ -306,7 +306,7 @@ pub enum PropertyValue {
},
Url {
id: PropertyId,
url: String,
url: Option<String>,
},
Email {
id: PropertyId,
Expand Down
18 changes: 15 additions & 3 deletions src/models/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,13 +263,25 @@ pub enum PropertyCondition {
And(Vec<PropertyCondition>),
}

pub trait Foo {}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

testing?


#[derive(Serialize, Debug, Eq, PartialEq, Clone)]
#[serde(rename_all = "lowercase")]
pub enum CompoundFilter<T: Foo> {
And(Vec<T>),
Or(Vec<T>),
}

#[derive(Serialize, Debug, Eq, PartialEq, Clone)]
pub struct FilterCondition {
pub property: String,
#[serde(flatten)]
pub condition: PropertyCondition,
}

impl <T: Foo> Foo for CompoundFilter<T>{}
impl Foo for FilterCondition{}

#[derive(Serialize, Debug, Eq, PartialEq, Hash, Copy, Clone)]
#[serde(rename_all = "snake_case")]
pub enum DatabaseSortTimestamp {
Expand All @@ -291,16 +303,16 @@ pub struct DatabaseSort {
}

#[derive(Serialize, Debug, Eq, PartialEq, Default, Clone)]
pub struct DatabaseQuery {
pub struct DatabaseQuery<T: Foo> {
#[serde(skip_serializing_if = "Option::is_none")]
pub sorts: Option<Vec<DatabaseSort>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub filter: Option<FilterCondition>,
pub filter: Option<T>,
#[serde(flatten)]
pub paging: Option<Paging>,
}

impl Pageable for DatabaseQuery {
impl <T: Foo> Pageable for DatabaseQuery<T> {
fn start_from(self, starting_point: Option<PagingCursor>) -> Self {
DatabaseQuery {
paging: Some(Paging {
Expand Down