tetratto/crates/core/src/model/journals.rs

83 lines
2.1 KiB
Rust
Raw Normal View History

use serde::{Serialize, Deserialize};
use tetratto_shared::{snow::Snowflake, unix_epoch_timestamp};
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
pub enum JournalPrivacyPermission {
/// Can be accessed by anyone via link.
Public,
/// Visible only to the journal owner.
Private,
}
impl Default for JournalPrivacyPermission {
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,
pub privacy: JournalPrivacyPermission,
2025-06-21 19:44:28 -04:00
/// An array of directories notes can be placed in.
///
/// `Vec<(id, parent id, name)>`
pub dirs: Vec<(usize, usize, String)>,
}
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,
privacy: JournalPrivacyPermission::default(),
2025-06-21 19:44:28 -04:00
dirs: Vec::new(),
}
}
}
#[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,
2025-06-21 19:44:28 -04:00
/// The "id" of the directoryy this note is in.
///
/// Directories are held in the journal in the `dirs` column.
pub dir: usize,
/// An array of tags associated with the note.
pub tags: Vec<String>,
}
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,
2025-06-21 19:44:28 -04:00
dir: 0,
tags: Vec::new(),
}
}
}