tetratto_core/model/
journals.rs1use serde::{Serialize, Deserialize};
2use tetratto_shared::{snow::Snowflake, unix_epoch_timestamp};
3
4#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
5pub enum JournalPrivacyPermission {
6 Public,
8 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 pub dirs: Vec<(usize, usize, String)>,
29}
30
31impl Journal {
32 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 pub journal: usize,
55 pub content: String,
56 pub edited: usize,
57 pub dir: usize,
61 pub tags: Vec<String>,
63 pub is_global: bool,
64}
65
66impl Note {
67 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}