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

solution_image.rs42 lines, 1.6 KiBHistoryRawDownload
1//! The photo of an offered solution — one optional image row per solution,
2//! the single-slot spelling of [`crate::domain::question_image`]'s
3//! child-table shape. The row carries metadata only; the bytes live on disk
4//! under [`crate::config::Config::files_path`] in a file named by `file` — a
5//! fresh server-generated id per upload, so a replace never overwrites bytes
6//! in place. The solution row itself carries no image columns; the child row
7//! is the whole photo. The writes ride the parent's own transactions in
8//! [`crate::db::solution`] (unconditional — solutions are unmoderated); the
9//! reads live in [`crate::db::solution_image`]; the web layer owns the blob
10//! I/O and its ordering (new blob before row, row before old blob).
11
12use crate::domain::note_file::FileContentType;
13use crate::domain::solution::SolutionId;
14
15/// One solution's photo row. `solution` is the primary key — one image per
16/// solution by construction, and a replace is a plain upsert.
17#[derive(Debug, Clone, sqlx::FromRow)]
18pub struct SolutionImage {
19 pub(crate) solution: SolutionId,
20 /// The blob's on-disk name — a fresh server-generated id every upload.
21 pub(crate) file: String,
22 pub(crate) content_type: FileContentType,
23 pub(crate) size: i64,
24}
25
26impl SolutionImage {
27 pub fn get_solution(&self) -> &SolutionId {
28 &self.solution
29 }
30
31 pub fn get_file(&self) -> &str {
32 &self.file
33 }
34
35 pub fn get_content_type(&self) -> &FileContentType {
36 &self.content_type
37 }
38
39 pub fn get_size(&self) -> i64 {
40 self.size
41 }
42}