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

mod.rs134 lines, 3.8 KiBHistoryRawDownload
1//! Domain layer: every value is a validated newtype, and each entity owns its
2//! own persistence. Row structs derive `sqlx::FromRow` so the exact same typed
3//! value flows from HTTP input all the way into PostgreSQL; transparent
4//! newtypes derive `sqlx::Type` so a column reads straight into the validated
5//! wrapper.
6
7pub mod academic_year;
8pub mod answer_image;
9pub mod appointment;
10pub mod appointment_slot;
11pub mod attendance;
12pub mod badge;
13pub mod bank_question;
14pub mod bank_question_image;
15pub mod board;
16pub mod board_stroke;
17pub mod builder;
18pub mod calendar;
19pub mod chatbot_message;
20pub mod chatbot_thread;
21pub mod class_blueprint;
22pub mod class_course;
23pub mod class_group;
24pub mod class_member;
25pub mod course;
26pub mod course_membership;
27pub mod course_note;
28pub mod course_note_file;
29pub mod course_offering;
30pub mod course_session;
31pub mod dietary_profile;
32pub mod enrollment;
33pub mod event;
34pub mod exam;
35pub mod exam_answer;
36pub mod exam_attempt;
37pub mod exam_question;
38pub mod exam_result;
39pub mod exam_weight;
40pub mod fee_plan;
41pub mod fee_plan_assignment;
42pub mod grade;
43pub mod holiday;
44pub mod homework;
45pub mod homework_file;
46pub mod homework_result;
47pub mod homework_submission;
48pub mod key;
49pub mod meal_attendance;
50pub mod meal_booking;
51pub mod meal_ledger;
52pub mod menu;
53pub mod menu_dish;
54pub mod message;
55pub mod monotonic_id;
56pub mod note;
57pub mod note_file;
58pub mod offering_subject;
59pub mod parent_link;
60pub mod payment_ledger;
61pub mod person;
62pub mod podcast_job;
63pub mod pomodoro;
64pub mod pool_question;
65pub mod pool_question_image;
66pub mod preferences;
67pub mod profile;
68pub mod question_image;
69pub mod rag_message;
70pub mod rag_output;
71pub mod rag_thread;
72pub mod registration;
73pub mod role;
74pub mod session;
75pub mod session_attendance;
76pub mod settings;
77pub mod solution;
78pub mod solution_image;
79pub mod subject;
80pub mod term;
81pub mod text_fold;
82pub mod timestamp;
83pub mod user;
84pub mod weekly_slot;
85pub mod work_entry;
86
87/// Fallback for lowercase-string enums whose `#[sqlx(type_name = "TEXT",
88/// rename_all = "lowercase")]` derive the `sqlx::Type` macro rejects (an
89/// exotic shape, not a plain C-like enum). Emits the same thing the derive
90/// would: `Type` reporting `TEXT`, `Encode` writing the lowercase name,
91/// `Decode` reading a TEXT value back and refusing an unknown one as a decode
92/// error — never a panic. Unused today: every current enum derives fine; kept
93/// so the fallback shape stays one `macro_rules!` away, identically across
94/// the domain.
95#[allow(unused_macros)]
96macro_rules! text_enum {
97 ($name:ident { $($variant:ident),+ $(,)? }) => {
98 impl sqlx::Type<sqlx::Postgres> for $name {
99 fn type_info() -> sqlx::postgres::PgTypeInfo {
100 sqlx::postgres::PgTypeInfo::with_name("TEXT")
101 }
102 }
103
104 impl<'r> sqlx::Decode<'r, sqlx::Postgres> for $name {
105 fn decode(
106 value: sqlx::postgres::PgValueRef<'r>,
107 ) -> Result<Self, sqlx::error::BoxDynError> {
108 let text: &str = sqlx::Decode::<sqlx::Postgres>::decode(value)?;
109 match text {
110 $(stringify!($variant) => Ok(Self::$variant),)+
111 other => Err(format!(
112 concat!("unknown ", stringify!($name), " value: `{}`"),
113 other
114 )
115 .into()),
116 }
117 }
118 }
119
120 impl<'q> sqlx::Encode<'q, sqlx::Postgres> for $name {
121 fn encode_by_ref(
122 &self,
123 buf: &mut sqlx::postgres::PgArgumentBuffer,
124 ) -> Result<sqlx::encode::IsNull, sqlx::error::BoxDynError> {
125 sqlx::Encode::<sqlx::Postgres>::encode(
126 match self {
127 $(Self::$variant => stringify!($variant),)+
128 },
129 buf,
130 )
131 }
132 }
133 };
134}