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

answer_image.rs46 lines, 1.5 KiBHistoryRawDownload
1//! The drawn-answer workflows: the doors the web layer takes for every
2//! answer-image read and write. The blob I/O and its disk ordering stay in
3//! the web layer; the row transactions live in [`crate::db::answer_image`].
4
5use crate::database::Database;
6use crate::db;
7use crate::domain::answer_image::AnswerImage;
8use crate::domain::exam::ExamId;
9use crate::domain::exam_question::ExamQuestionId;
10use crate::domain::user::UserId;
11use crate::error::AppError;
12
13/// Create or replace the student's drawing for the question, handing back
14/// what it stored plus the blob name it replaced, for the caller to take
15/// off disk.
16pub async fn upsert(
17 db: &Database,
18 image: AnswerImage,
19) -> Result<(AnswerImage, Option<String>), AppError> {
20 db::answer_image::upsert(db, image).await
21}
22
23/// The student's drawing for one question in one sitting, if any.
24pub async fn read(
25 db: &Database,
26 question: &ExamQuestionId,
27 user: &UserId,
28 seq: i64,
29) -> Result<Option<AnswerImage>, AppError> {
30 db::answer_image::read(db, question, user, seq).await
31}
32
33/// Drop one drawing — the returned row names the blob to unlink.
34pub async fn delete(db: &Database, image: AnswerImage) -> Result<AnswerImage, AppError> {
35 db::answer_image::delete(db, image).await
36}
37
38/// One student's answer drawings for a single sitting.
39pub async fn list_for_exam_user(
40 db: &Database,
41 exam: &ExamId,
42 user: &UserId,
43 seq: i64,
44) -> Result<Vec<AnswerImage>, AppError> {
45 db::answer_image::list_for_exam_user(db, exam, user, seq).await
46}