2025-06-18 19:21:01 -04:00
|
|
|
use serde::{Serialize, Deserialize};
|
|
|
|
use tetratto_shared::{snow::Snowflake, unix_epoch_timestamp};
|
|
|
|
|
|
|
|
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
|
2025-06-18 21:00:07 -04:00
|
|
|
pub enum JournalPrivacyPermission {
|
2025-06-18 19:21:01 -04:00
|
|
|
/// Can be accessed by anyone via link.
|
|
|
|
Public,
|
|
|
|
/// Visible only to the journal owner.
|
|
|
|
Private,
|
|
|
|
}
|
|
|
|
|
2025-06-18 21:00:07 -04:00
|
|
|
impl Default for JournalPrivacyPermission {
|
2025-06-18 19:21:01 -04:00
|
|
|
fn default() -> Self {
|
|
|
|
Self::Private
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
|
|
|
pub struct Journal {
|
|
|
|
pub id: usize,
|
|
|
|
pub created: usize,
|
|
|
|
pub owner: usize,
|
|
|
|
pub title: String,
|
2025-06-18 21:00:07 -04:00
|
|
|
pub privacy: JournalPrivacyPermission,
|
2025-06-18 19:21:01 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Journal {
|
|
|
|
/// Create a new [`Journal`].
|
|
|
|
pub fn new(owner: usize, title: String) -> Self {
|
|
|
|
Self {
|
|
|
|
id: Snowflake::new().to_string().parse::<usize>().unwrap(),
|
|
|
|
created: unix_epoch_timestamp(),
|
|
|
|
owner,
|
|
|
|
title,
|
2025-06-18 21:00:07 -04:00
|
|
|
privacy: JournalPrivacyPermission::default(),
|
2025-06-18 19:21:01 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
|
|
|
pub struct Note {
|
|
|
|
pub id: usize,
|
|
|
|
pub created: usize,
|
|
|
|
pub owner: usize,
|
|
|
|
pub title: String,
|
|
|
|
/// The ID of the [`Journal`] this note belongs to.
|
|
|
|
///
|
|
|
|
/// The note is subject to the settings set for the journal it's in.
|
|
|
|
pub journal: usize,
|
|
|
|
pub content: String,
|
|
|
|
pub edited: usize,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Note {
|
|
|
|
/// Create a new [`Note`].
|
|
|
|
pub fn new(owner: usize, title: String, journal: usize, content: String) -> Self {
|
|
|
|
let created = unix_epoch_timestamp();
|
|
|
|
|
|
|
|
Self {
|
|
|
|
id: Snowflake::new().to_string().parse::<usize>().unwrap(),
|
|
|
|
created,
|
|
|
|
owner,
|
|
|
|
title,
|
|
|
|
journal,
|
|
|
|
content,
|
|
|
|
edited: created,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|