add: full journals api
add: full notes api
This commit is contained in:
parent
102ea0ee35
commit
42421bd906
11 changed files with 476 additions and 12 deletions
|
@ -1,7 +1,7 @@
|
|||
CREATE TABLE IF NOT EXISTS channels (
|
||||
CREATE TABLE IF NOT EXISTS journals (
|
||||
id BIGINT NOT NULL PRIMARY KEY,
|
||||
created BIGINT NOT NULL,
|
||||
owner BIGINT NOT NULL,
|
||||
title TEXT NOT NULL,
|
||||
view TEXT NOT NULL
|
||||
privacy TEXT NOT NULL
|
||||
)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
CREATE TABLE IF NOT EXISTS channels (
|
||||
CREATE TABLE IF NOT EXISTS notes (
|
||||
id BIGINT NOT NULL PRIMARY KEY,
|
||||
created BIGINT NOT NULL,
|
||||
owner BIGINT NOT NULL,
|
||||
|
|
|
@ -3,7 +3,7 @@ use crate::{
|
|||
model::{
|
||||
auth::User,
|
||||
permissions::FinePermission,
|
||||
journals::{Journal, JournalViewPermission},
|
||||
journals::{Journal, JournalPrivacyPermission},
|
||||
Error, Result,
|
||||
},
|
||||
};
|
||||
|
@ -18,7 +18,7 @@ impl DataManager {
|
|||
created: get!(x->1(i64)) as usize,
|
||||
owner: get!(x->2(i64)) as usize,
|
||||
title: get!(x->3(String)),
|
||||
view: serde_json::from_str(&get!(x->4(String))).unwrap(),
|
||||
privacy: serde_json::from_str(&get!(x->4(String))).unwrap(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -36,7 +36,7 @@ impl DataManager {
|
|||
|
||||
let res = query_rows!(
|
||||
&conn,
|
||||
"SELECT * FROM journals WHERE owner = $1 ORDER BY name ASC",
|
||||
"SELECT * FROM journals WHERE owner = $1 ORDER BY title ASC",
|
||||
&[&(id as i64)],
|
||||
|x| { Self::get_journal_from_row(x) }
|
||||
);
|
||||
|
@ -89,7 +89,7 @@ impl DataManager {
|
|||
&(data.created as i64),
|
||||
&(data.owner as i64),
|
||||
&data.title,
|
||||
&serde_json::to_string(&data.view).unwrap(),
|
||||
&serde_json::to_string(&data.privacy).unwrap(),
|
||||
]
|
||||
);
|
||||
|
||||
|
@ -137,5 +137,5 @@ impl DataManager {
|
|||
}
|
||||
|
||||
auto_method!(update_journal_title(&str)@get_journal_by_id:MANAGE_JOURNALS -> "UPDATE journals SET title = $1 WHERE id = $2" --cache-key-tmpl="atto.journal:{}");
|
||||
auto_method!(update_journal_view(JournalViewPermission)@get_journal_by_id:MANAGE_JOURNALS -> "UPDATE journals SET privacy = $1 WHERE id = $2" --serde --cache-key-tmpl="atto.journal:{}");
|
||||
auto_method!(update_journal_privacy(JournalPrivacyPermission)@get_journal_by_id:MANAGE_JOURNALS -> "UPDATE journals SET privacy = $1 WHERE id = $2" --serde --cache-key-tmpl="atto.journal:{}");
|
||||
}
|
||||
|
|
|
@ -121,4 +121,5 @@ impl DataManager {
|
|||
}
|
||||
|
||||
auto_method!(update_note_title(&str)@get_note_by_id:MANAGE_NOTES -> "UPDATE notes SET title = $1 WHERE id = $2" --cache-key-tmpl="atto.note:{}");
|
||||
auto_method!(update_note_content(&str)@get_note_by_id:MANAGE_NOTES -> "UPDATE notes SET content = $1 WHERE id = $2" --cache-key-tmpl="atto.note:{}");
|
||||
}
|
||||
|
|
|
@ -2,14 +2,14 @@ use serde::{Serialize, Deserialize};
|
|||
use tetratto_shared::{snow::Snowflake, unix_epoch_timestamp};
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
|
||||
pub enum JournalViewPermission {
|
||||
pub enum JournalPrivacyPermission {
|
||||
/// Can be accessed by anyone via link.
|
||||
Public,
|
||||
/// Visible only to the journal owner.
|
||||
Private,
|
||||
}
|
||||
|
||||
impl Default for JournalViewPermission {
|
||||
impl Default for JournalPrivacyPermission {
|
||||
fn default() -> Self {
|
||||
Self::Private
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ pub struct Journal {
|
|||
pub created: usize,
|
||||
pub owner: usize,
|
||||
pub title: String,
|
||||
pub view: JournalViewPermission,
|
||||
pub privacy: JournalPrivacyPermission,
|
||||
}
|
||||
|
||||
impl Journal {
|
||||
|
@ -32,7 +32,7 @@ impl Journal {
|
|||
created: unix_epoch_timestamp(),
|
||||
owner,
|
||||
title,
|
||||
view: JournalViewPermission::default(),
|
||||
privacy: JournalPrivacyPermission::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -62,6 +62,12 @@ pub enum AppScope {
|
|||
UserReadRequests,
|
||||
/// Read questions as the user.
|
||||
UserReadQuestions,
|
||||
/// Read the user's stacks.
|
||||
UserReadStacks,
|
||||
/// Read the user's journals.
|
||||
UserReadJournals,
|
||||
/// Read the user's notes.
|
||||
UserReadNotes,
|
||||
/// Create posts as the user.
|
||||
UserCreatePosts,
|
||||
/// Create messages as the user.
|
||||
|
@ -76,6 +82,10 @@ pub enum AppScope {
|
|||
UserCreateCommunities,
|
||||
/// Create stacks on behalf of the user.
|
||||
UserCreateStacks,
|
||||
/// Create journals on behalf of the user.
|
||||
UserCreateJournals,
|
||||
/// Create notes on behalf of the user.
|
||||
UserCreateNotes,
|
||||
/// Delete posts owned by the user.
|
||||
UserDeletePosts,
|
||||
/// Delete messages owned by the user.
|
||||
|
@ -106,6 +116,10 @@ pub enum AppScope {
|
|||
UserManageRequests,
|
||||
/// Manage the user's uploads.
|
||||
UserManageUploads,
|
||||
/// Manage the user's journals.
|
||||
UserManageJournals,
|
||||
/// Manage the user's notes.
|
||||
UserManageNotes,
|
||||
/// Edit posts created by the user.
|
||||
UserEditPosts,
|
||||
/// Edit drafts created by the user.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue