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

course_note.rs55 lines, 1.8 KiBHistoryRawDownload
1//! Course-note workflows: the create/read/list/update/delete paths the
2//! course-notes surface drives. The queries live in
3//! [`crate::db::course_note`]; blob unlinking and the AI re-index stay in the
4//! web layer.
5
6use crate::database::Database;
7use crate::db::course_note;
8use crate::domain::course::CourseId;
9use crate::domain::course_note::{CourseNote, CourseNoteContent, CourseNoteId, CourseNoteTitle};
10use crate::domain::course_note_file::CourseNoteFile;
11use crate::domain::user::UserId;
12use crate::error::AppError;
13
14pub async fn create(
15 db: &Database,
16 course: &CourseId,
17 author: &UserId,
18 title: CourseNoteTitle,
19 content: CourseNoteContent,
20) -> Result<CourseNote, AppError> {
21 course_note::create(db, course, author, title, content).await
22}
23
24pub async fn read(db: &Database, id: &CourseNoteId) -> Result<Option<CourseNote>, AppError> {
25 course_note::read(db, id).await
26}
27
28pub async fn list_for_course(
29 db: &Database,
30 course: &CourseId,
31 limit: Option<i64>,
32 offset: i64,
33) -> Result<(Vec<CourseNote>, i64), AppError> {
34 course_note::list_for_course(db, course, limit, offset).await
35}
36
37/// Only what the request carried is written: an omitted field (`None`) is
38/// not stored at all, so a concurrent edit of the other field survives.
39pub async fn update(
40 db: &Database,
41 note: CourseNote,
42 title: Option<CourseNoteTitle>,
43 content: Option<CourseNoteContent>,
44) -> Result<CourseNote, AppError> {
45 course_note::update(db, note, title, content).await
46}
47
48/// Delete the note and cascade its attachment rows; the returned files are
49/// exactly whose blobs the caller may unlink.
50pub async fn delete(
51 db: &Database,
52 note: CourseNote,
53) -> Result<(CourseNote, Vec<CourseNoteFile>), AppError> {
54 course_note::delete(db, note).await
55}