hezarfen_backend
Clone
https://git.tahinli.com/archive/hezarfen_backend.git
0 watching0 forksRust8.3 MiB6d68754Ahmet Kaan Gümüş2 months ago566 commits
| 1 | //! The syllabus selection junctions: `offering_subject` (what the grade-level |
| 2 | //! template teaches) and `class_course_subject` (what one section teaches for |
| 3 | //! itself), over the subject rows of [`crate::db::subject`]. The row types are |
| 4 | //! the subjects themselves — a selection is only membership — so every read |
| 5 | //! here answers `Vec<Subject>` in the resolved listing order: **by subject |
| 6 | //! name, then subject id** (deterministic under any insert order). |
| 7 | //! |
| 8 | //! The class-side writes are the override machinery: each is **one |
| 9 | //! data-modifying-CTE statement** that flips `class_course.subjects_inherited` |
| 10 | //! in the same breath it inserts, deletes or sweeps the section's rows — the |
| 11 | //! flag can never drift from the table it governs, and this module never |
| 12 | //! touches `class_course` outside that flag. The reset is the same shape in |
| 13 | //! reverse: sweep the rows, flip the flag back to TRUE, one statement. |
| 14 | |
| 15 | use crateDatabase; |
| 16 | use crateClassCourseId; |
| 17 | use crateCourseId; |
| 18 | use crateCourseOfferingId; |
| 19 | use crate; |
| 20 | use crateAppError; |
| 21 | |
| 22 | /// Map the junctions' foreign-key refusals to the caller's 404: an offering, |
| 23 | /// a section or a subject deleted between the service's up-front read and |
| 24 | /// this write cannot half-land (the same mapping |
| 25 | /// [`crate::db::subject::create`] uses for its course key). |
| 26 | |
| 27 | |
| 28 | |
| 29 | |
| 30 | |
| 31 | |
| 32 | |
| 33 | |
| 34 | /// The offering's selected topics, name-then-id order. |
| 35 | pub async |
| 36 | |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | |
| 42 | |
| 43 | |
| 44 | |
| 45 | |
| 46 | |
| 47 | |
| 48 | |
| 49 | |
| 50 | |
| 51 | |
| 52 | |
| 53 | |
| 54 | |
| 55 | |
| 56 | /// The section's own selected topics — authoritative only while |
| 57 | /// `subjects_inherited` is FALSE, and empty-list-is-a-set then — name-then-id |
| 58 | /// order. |
| 59 | pub async |
| 60 | |
| 61 | |
| 62 | |
| 63 | |
| 64 | |
| 65 | |
| 66 | |
| 67 | |
| 68 | |
| 69 | |
| 70 | |
| 71 | |
| 72 | |
| 73 | |
| 74 | |
| 75 | |
| 76 | |
| 77 | |
| 78 | |
| 79 | |
| 80 | /// Add one topic to the offering's selection. Idempotent: re-adding a |
| 81 | /// selection the offering already holds writes nothing and answers `false` |
| 82 | /// (`true` = newly added), matching the junction idiom. |
| 83 | pub async |
| 84 | |
| 85 | |
| 86 | |
| 87 | |
| 88 | |
| 89 | |
| 90 | |
| 91 | |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 | |
| 97 | |
| 98 | |
| 99 | |
| 100 | |
| 101 | /// Drop one topic from the offering's selection. `false` when it was not |
| 102 | /// selected — an honest nothing-changed, which the service answers as a 404. |
| 103 | pub async |
| 104 | |
| 105 | |
| 106 | |
| 107 | |
| 108 | |
| 109 | |
| 110 | |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | |
| 116 | |
| 117 | |
| 118 | |
| 119 | /// Add one topic to the section's own set, flipping `subjects_inherited` to |
| 120 | /// FALSE **in the same statement** — the insert and the override switch are |
| 121 | /// one data-modifying-CTE unit, so a reader can never see a class-owned row |
| 122 | /// under a still-inheriting flag. Idempotent like the offering side: the |
| 123 | /// second add of one topic writes no row (`added` = false) but the intent — |
| 124 | /// "this section owns its set" — still stands, so the flip is unconditional |
| 125 | /// on a live instance. `live` = false means the instance vanished mid-flight; |
| 126 | /// the service answers that 404. |
| 127 | pub async |
| 128 | |
| 129 | |
| 130 | |
| 131 | |
| 132 | |
| 133 | |
| 134 | |
| 135 | |
| 136 | |
| 137 | |
| 138 | |
| 139 | |
| 140 | |
| 141 | |
| 142 | |
| 143 | |
| 144 | |
| 145 | |
| 146 | |
| 147 | |
| 148 | |
| 149 | |
| 150 | |
| 151 | |
| 152 | |
| 153 | |
| 154 | |
| 155 | |
| 156 | /// Drop one topic from the section's own set, flipping `subjects_inherited` |
| 157 | /// to FALSE in the same statement — but **only when a row actually went**: |
| 158 | /// a delete that finds nothing flips nothing, so the service can answer 404 |
| 159 | /// for a missing selection without a stray side effect on the flag. (`live` |
| 160 | /// = false: the instance is gone mid-flight.) |
| 161 | pub async |
| 162 | |
| 163 | |
| 164 | |
| 165 | |
| 166 | |
| 167 | |
| 168 | |
| 169 | |
| 170 | |
| 171 | |
| 172 | |
| 173 | |
| 174 | |
| 175 | |
| 176 | |
| 177 | |
| 178 | |
| 179 | |
| 180 | |
| 181 | |
| 182 | |
| 183 | |
| 184 | |
| 185 | |
| 186 | |
| 187 | /// The reset door: sweep every class-owned row and flip |
| 188 | /// `subjects_inherited` back to TRUE — one statement, so the set and its |
| 189 | /// switch agree at every instant. The flip is unconditional on a live |
| 190 | /// instance: clearing an already-empty own set is exactly the request that |
| 191 | /// must restore inheritance. Answers the swept row count; `live` = false |
| 192 | /// means the instance vanished mid-flight. |
| 193 | pub async |
| 194 | |
| 195 | |
| 196 | |
| 197 | |
| 198 | |
| 199 | |
| 200 | |
| 201 | |
| 202 | |
| 203 | |
| 204 | |
| 205 | |
| 206 | |
| 207 | |
| 208 | |
| 209 | |
| 210 | |
| 211 | |
| 212 | |
| 213 | |
| 214 | |
| 215 | |
| 216 | |
| 217 | /// The resolved-membership probe behind the exam-question/homework tag rewire: |
| 218 | /// does `subject` sit in what this section *teaches* — its own rows while |
| 219 | /// `subjects_inherited` is FALSE, else the offering's set? One statement, so |
| 220 | /// the flag and the rows it reads agree as of one snapshot. `None` = the |
| 221 | /// instance is gone. |
| 222 | pub async |
| 223 | |
| 224 | |
| 225 | |
| 226 | |
| 227 | |
| 228 | |
| 229 | |
| 230 | |
| 231 | |
| 232 | |
| 233 | |
| 234 | |
| 235 | |
| 236 | |
| 237 | |
| 238 | |
| 239 | |
| 240 | |
| 241 | |
| 242 | |
| 243 | |
| 244 |