forge
Explore
Log in

Don't you dare go Hollow

hezarfen_backend

Clone
★ 0

0 watching0 forksRust8.3 MiB6d68754Ahmet Kaan Gümüş2 months ago566 commits

note.rs54 lines, 1.6 KiBHistoryRawDownload
1//! Note workflows: the create/read/list/update/delete paths the notes
2//! surface drives, all scoped to the owning user. The queries live in
3//! [`crate::db::note`]; blob unlinking stays in the web layer.
4
5use crate::database::Database;
6use crate::db::note;
7use crate::domain::note::{Note, NoteContent, NoteId, NoteTitle};
8use crate::domain::note_file::NoteFile;
9use crate::domain::user::UserId;
10use crate::error::AppError;
11
12pub async fn create(
13 db: &Database,
14 owner: &UserId,
15 title: NoteTitle,
16 content: NoteContent,
17) -> Result<Note, AppError> {
18 note::create(db, owner, title, content).await
19}
20
21/// Read a note only if it belongs to `owner`.
22pub async fn read_owned(
23 db: &Database,
24 id: &NoteId,
25 owner: &UserId,
26) -> Result<Option<Note>, AppError> {
27 note::read_owned(db, id, owner).await
28}
29
30pub async fn list_for(
31 db: &Database,
32 owner: &UserId,
33 limit: Option<i64>,
34 offset: i64,
35) -> Result<(Vec<Note>, i64), AppError> {
36 note::list_for(db, owner, limit, offset).await
37}
38
39/// Only what the request carried is written: an omitted field (`None`) is
40/// not stored at all, so a concurrent edit of the other field survives.
41pub async fn update(
42 db: &Database,
43 note: Note,
44 title: Option<NoteTitle>,
45 content: Option<NoteContent>,
46) -> Result<Note, AppError> {
47 note::update(db, note, title, content).await
48}
49
50/// Delete the note and cascade its attachment rows; the returned files are
51/// exactly whose blobs the caller may unlink.
52pub async fn delete(db: &Database, note: Note) -> Result<(Note, Vec<NoteFile>), AppError> {
53 note::delete(db, note).await
54}