add: journal entry context

This commit is contained in:
trisua 2025-03-24 20:23:52 -04:00
parent e87ad74d43
commit 1a6b48078a
5 changed files with 57 additions and 3 deletions

View file

@ -3,5 +3,6 @@ CREATE TABLE IF NOT EXISTS entries (
created INTEGER NOT NULL,
content TEXT NOT NULL,
owner INTEGER NOT NULL,
journal INTEGER NOT NULL
journal INTEGER NOT NULL,
context TEXT NOT NULL
)

View file

@ -1,5 +1,6 @@
use super::*;
use crate::cache::Cache;
use crate::model::journal::JournalEntryContext;
use crate::model::{
Error, Result, auth::User, journal::JournalEntry, journal::JournalPageWriteAccess,
permissions::FinePermission,
@ -24,6 +25,7 @@ impl DataManager {
content: get!(x->2(String)),
owner: get!(x->3(u64)) as usize,
journal: get!(x->4(u64)) as usize,
context: serde_json::from_str(&get!(x->5(String))).unwrap(),
}
}
@ -79,6 +81,7 @@ impl DataManager {
&data.content.as_str(),
&data.owner.to_string().as_str(),
&data.journal.to_string().as_str(),
&serde_json::to_string(&data.context).unwrap().as_str(),
]
);
@ -91,4 +94,5 @@ impl DataManager {
auto_method!(delete_entry()@get_entry_by_id:MANAGE_JOURNAL_ENTRIES -> "DELETE FROM entries WHERE id = $1" --cache-key-tmpl="atto.entry:{}");
auto_method!(update_entry_content(String)@get_entry_by_id:MANAGE_JOURNAL_ENTRIES -> "UPDATE entries SET content = $1 WHERE id = $2" --cache-key-tmpl="atto.entry:{}");
auto_method!(update_entry_context(JournalEntryContext)@get_entry_by_id:MANAGE_JOURNAL_ENTRIES -> "UPDATE entries SET context = $1 WHERE id = $2" --serde --cache-key-tmpl="atto.entry:{}");
}

View file

@ -100,6 +100,19 @@ impl JournalPageMembership {
}
}
#[derive(Serialize, Deserialize)]
pub struct JournalEntryContext {
pub comments_enabled: bool,
}
impl Default for JournalEntryContext {
fn default() -> Self {
Self {
comments_enabled: true,
}
}
}
#[derive(Serialize, Deserialize)]
pub struct JournalEntry {
pub id: usize,
@ -109,6 +122,8 @@ pub struct JournalEntry {
pub owner: usize,
/// The ID of the [`JournalPage`] this entry belongs to.
pub journal: usize,
/// Extra information about the journal entry.
pub context: JournalEntryContext,
}
impl JournalEntry {
@ -123,6 +138,7 @@ impl JournalEntry {
content,
owner,
journal,
context: JournalEntryContext::default(),
}
}
}