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_file.rs39 lines, 1.2 KiBHistoryRawDownload
1//! Note-file workflows: the attachment paths the notes surface drives. The
2//! queries live in [`crate::db::note_file`]; blob unlinking stays in the web
3//! layer.
4
5use crate::database::Database;
6use crate::db::note_file;
7use crate::domain::note::NoteId;
8use crate::domain::note_file::{NoteFile, NoteFileId};
9use crate::error::AppError;
10
11/// Persist a row assembled by [`NoteFile::new`]; refuses with a conflict once
12/// the note holds its cap.
13pub async fn insert(db: &Database, file: NoteFile) -> Result<NoteFile, AppError> {
14 note_file::insert(db, file).await
15}
16
17/// Read a file's row only if it belongs to `note`.
18pub async fn read_for(
19 db: &Database,
20 id: &NoteFileId,
21 note: &NoteId,
22) -> Result<Option<NoteFile>, AppError> {
23 note_file::read_for(db, id, note).await
24}
25
26pub async fn list_for(
27 db: &Database,
28 note: &NoteId,
29 limit: Option<i64>,
30 offset: i64,
31) -> Result<(Vec<NoteFile>, i64), AppError> {
32 note_file::list_for(db, note, limit, offset).await
33}
34
35/// Delete the row and hand its slot back in the same transaction; the returned
36/// row is exactly whose blob the caller may unlink.
37pub async fn delete(db: &Database, file: NoteFile) -> Result<NoteFile, AppError> {
38 note_file::delete(db, file).await
39}