use chrono::{DateTime, Utc}; use derive_builder::Builder; use serde::{Deserialize, Serialize}; use sqlx::{self, FromRow}; #[derive(Clone, Serialize, Deserialize, Debug, FromRow)] pub struct RawPage { pub id: i64, pub slug: String, pub title: String, pub note_id: i64, pub creation_date: DateTime, pub updated_date: DateTime, pub lastview_date: DateTime, pub deleted_date: Option>, } #[derive(Clone, Serialize, Deserialize, Debug, FromRow)] pub struct RawNote { pub id: i64, pub uuid: String, pub parent_id: i64, pub parent_uuid: String, pub content: String, pub position: i64, pub notetype: String, pub creation_date: DateTime, pub updated_date: DateTime, pub lastview_date: DateTime, pub deleted_date: Option>, } #[derive(Clone, Serialize, Deserialize, Debug, Builder)] pub struct NewPage { pub slug: String, pub title: String, pub note_id: i64, #[builder(default = r#"chrono::Utc::now()"#)] pub creation_date: DateTime, #[builder(default = r#"chrono::Utc::now()"#)] pub updated_date: DateTime, #[builder(default = r#"chrono::Utc::now()"#)] pub lastview_date: DateTime, #[builder(default = r#"None"#)] pub deleted_date: Option>, } #[derive(Clone, Serialize, Deserialize, Debug, Builder)] pub struct NewNote { #[builder(default = r#""".to_string()"#)] pub uuid: String, pub content: String, #[builder(default = r#""note".to_string()"#)] pub notetype: String, #[builder(default = r#"chrono::Utc::now()"#)] pub creation_date: DateTime, #[builder(default = r#"chrono::Utc::now()"#)] pub updated_date: DateTime, #[builder(default = r#"chrono::Utc::now()"#)] pub lastview_date: DateTime, #[builder(default = r#"None"#)] pub deleted_date: Option>, } #[derive(Clone, Serialize, Deserialize, Debug, FromRow)] pub(crate) struct JustSlugs { pub slug: String, } #[derive(Clone, Serialize, Deserialize, Debug, FromRow)] pub(crate) struct JustTitles { title: String, } #[derive(Clone, Serialize, Deserialize, Debug, FromRow)] pub(crate) struct JustId { pub id: i64, } #[derive(Clone, Serialize, Deserialize, Debug, FromRow)] pub(crate) struct PageTitles { pub id: i64, pub title: String, } #[derive(Clone, Serialize, Deserialize, Debug, FromRow)] pub(crate) struct NoteRelationship { pub parent_id: i64, pub note_id: i64, pub position: i64, pub nature: String, } #[derive(Clone, Serialize, Deserialize, Debug, FromRow)] pub(crate) struct RowCount { pub count: i64, } #[cfg(test)] mod tests { use super::*; #[test] fn can_build_new_note() { let now = chrono::Utc::now(); let newnote = NewNoteBuilder::default() .uuid("foo".to_string()) .content("bar".to_string()) .build() .unwrap(); assert!((newnote.creation_date - now).num_minutes() < 1); assert!((newnote.updated_date - now).num_minutes() < 1); assert!((newnote.lastview_date - now).num_minutes() < 1); assert!(newnote.deleted_date.is_none()); } }