tetratto_core/model/
journals.rs

1use serde::{Serialize, Deserialize};
2use tetratto_shared::{snow::Snowflake, unix_epoch_timestamp};
3
4#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
5pub enum JournalPrivacyPermission {
6    /// Can be accessed by anyone via link.
7    Public,
8    /// Visible only to the journal owner.
9    Private,
10}
11
12impl Default for JournalPrivacyPermission {
13    fn default() -> Self {
14        Self::Private
15    }
16}
17
18#[derive(Clone, Debug, Serialize, Deserialize)]
19pub struct Journal {
20    pub id: usize,
21    pub created: usize,
22    pub owner: usize,
23    pub title: String,
24    pub privacy: JournalPrivacyPermission,
25    /// An array of directories notes can be placed in.
26    ///
27    /// `Vec<(id, parent id, name)>`
28    pub dirs: Vec<(usize, usize, String)>,
29}
30
31impl Journal {
32    /// Create a new [`Journal`].
33    pub fn new(owner: usize, title: String) -> Self {
34        Self {
35            id: Snowflake::new().to_string().parse::<usize>().unwrap(),
36            created: unix_epoch_timestamp(),
37            owner,
38            title,
39            privacy: JournalPrivacyPermission::default(),
40            dirs: Vec::new(),
41        }
42    }
43}
44
45#[derive(Clone, Debug, Serialize, Deserialize)]
46pub struct Note {
47    pub id: usize,
48    pub created: usize,
49    pub owner: usize,
50    pub title: String,
51    /// The ID of the [`Journal`] this note belongs to.
52    ///
53    /// The note is subject to the settings set for the journal it's in.
54    pub journal: usize,
55    pub content: String,
56    pub edited: usize,
57    /// The "id" of the directoryy this note is in.
58    ///
59    /// Directories are held in the journal in the `dirs` column.
60    pub dir: usize,
61    /// An array of tags associated with the note.
62    pub tags: Vec<String>,
63    pub is_global: bool,
64}
65
66impl Note {
67    /// Create a new [`Note`].
68    pub fn new(owner: usize, title: String, journal: usize, content: String) -> Self {
69        let created = unix_epoch_timestamp();
70
71        Self {
72            id: Snowflake::new().to_string().parse::<usize>().unwrap(),
73            created,
74            owner,
75            title,
76            journal,
77            content,
78            edited: created,
79            dir: 0,
80            tags: Vec::new(),
81            is_global: false,
82        }
83    }
84}