hezarfen_backend
Clone
https://git.tahinli.com/Hezarfen/hezarfen_backend.git
0 watching0 forksRust8.3 MiB6d68754Ahmet Kaan Gümüş2 months ago566 commits
| 1 | //! The `class_course` table: the course-axis attach entry point and the |
| 2 | //! instance reads behind `/instances`. The refusals-to-errors policy and the |
| 3 | //! detach that turns a zero-row sweep into a 404 live in |
| 4 | //! [`crate::service::class_course`]; the transaction itself is the pump's, |
| 5 | //! [`crate::db::class_pump`]. |
| 6 | //! |
| 7 | //! An instance is the academic anchor now: it points at its grade-level |
| 8 | //! **offering** template, carries its own content *overrides* (title, |
| 9 | //! description, and the nullable `ders_saati` / `counts_toward_karne` — a |
| 10 | //! `NULL` inherits from the offering chain, so every read goes through |
| 11 | //! [`crate::service::class_course::resolve_policy`], never a blind unwrap), |
| 12 | //! the three `*_inherited` set flags, and the roster counter its own teachers |
| 13 | //! ([`crate::db::class_course_teacher`]). Reads speak the *bare uuid* id of |
| 14 | //! the instance; the (class, course) pair survives as the UNIQUE key the |
| 15 | //! attach gates on. |
| 16 | |
| 17 | use crateCLASS_COURSE_TABLE; |
| 18 | use crateDatabase; |
| 19 | use crateAttached; |
| 20 | use cratePagedList; |
| 21 | use crateClassBlueprintId; |
| 22 | use crate; |
| 23 | use crateClassGroupId; |
| 24 | use crate; |
| 25 | use crateCourseOfferingId; |
| 26 | use crateTimestamp; |
| 27 | use crateUserId; |
| 28 | use crateAppError; |
| 29 | |
| 30 | /// The projection every instance read shares. |
| 31 | /// |
| 32 | /// Three translations ride it: `source` is stored as the blueprint's surrogate |
| 33 | /// uuid while the domain speaks the grade label the API does (a hand attach, |
| 34 | /// source NULL, survives the LEFT JOIN as NULL), `ders_saati` is a *nullable* |
| 35 | /// `SMALLINT` column while [`DersSaati`] is an `i64` newtype — decoded |
| 36 | /// through a `bigint` cast so the type the driver checks is the one the |
| 37 | /// newtype names, its `NULL` meaning *inherit* — and the overrides/flags ride |
| 38 | /// along as their plain column shapes. |
| 39 | const INSTANCE_COLUMNS: &str = "cc.id, cc.class, cc.course, cc.offering, cc.attached_by, \ |
| 40 | b.grade_level AS source, cc.title, cc.description, \ |
| 41 | cc.ders_saati::bigint AS ders_saati, cc.counts_toward_karne, \ |
| 42 | cc.subjects_inherited, cc.exam_weights_inherited, cc.weekly_plan_inherited, \ |
| 43 | cc.enrollment_count, cc.attached_at"; |
| 44 | |
| 45 | /// The attach itself, with the refusals left *unmapped*. |
| 46 | /// |
| 47 | /// A hand attach ([`crate::service::class_course::attach`]) turns each of them |
| 48 | /// into the error the route answers with, because one call is one course and a |
| 49 | /// refusal is that call's whole answer. A blueprint pump cannot: it runs |
| 50 | /// one of these per (class, course), and a course that does not fit one |
| 51 | /// section must not abort the other eleven — so it needs to *read* the |
| 52 | /// refusal and carry on ([`crate::domain::class_blueprint`]). |
| 53 | /// |
| 54 | /// `source` is the provenance tag, and it is written by the same statement |
| 55 | /// that writes the link, so no attachment can exist without the answer to |
| 56 | /// "may a blueprint take this back". It is also *claimed* in that |
| 57 | /// transaction ([`Attached::SourceGone`]): a blueprint deleted while this |
| 58 | /// pump ran has already swept by that tag, so a row landing afterwards |
| 59 | /// would carry a name nothing can reach. |
| 60 | pub async |
| 61 | |
| 62 | |
| 63 | |
| 64 | |
| 65 | |
| 66 | |
| 67 | |
| 68 | |
| 69 | |
| 70 | /// The instances a class carries, newest first — by when they were attached, |
| 71 | /// the instance id breaking the tie (v7 ids sort in mint order, so the order |
| 72 | /// is total and reads as creation order within one instant). |
| 73 | pub async |
| 74 | |
| 75 | |
| 76 | |
| 77 | |
| 78 | |
| 79 | |
| 80 | |
| 81 | |
| 82 | |
| 83 | |
| 84 | |
| 85 | |
| 86 | |
| 87 | |
| 88 | |
| 89 | |
| 90 | |
| 91 | |
| 92 | /// The instances one catalog course is taught in, newest first — the read |
| 93 | /// behind "which sections run this course". |
| 94 | pub async |
| 95 | |
| 96 | |
| 97 | |
| 98 | |
| 99 | |
| 100 | |
| 101 | |
| 102 | |
| 103 | |
| 104 | |
| 105 | |
| 106 | |
| 107 | |
| 108 | |
| 109 | |
| 110 | |
| 111 | |
| 112 | |
| 113 | /// Every instance held by any of `classes` (one query, unpaged) — the join |
| 114 | /// half of the class-layer reads that already hold class ids (a roster read, |
| 115 | /// a blueprint status diff). Ids that name no class are simply absent from |
| 116 | /// the result. |
| 117 | pub async |
| 118 | |
| 119 | |
| 120 | |
| 121 | |
| 122 | |
| 123 | |
| 124 | |
| 125 | |
| 126 | |
| 127 | |
| 128 | |
| 129 | |
| 130 | |
| 131 | |
| 132 | |
| 133 | |
| 134 | |
| 135 | |
| 136 | |
| 137 | |
| 138 | |
| 139 | |
| 140 | |
| 141 | |
| 142 | |
| 143 | |
| 144 | |
| 145 | |
| 146 | |
| 147 | |
| 148 | |
| 149 | /// Every instance of any of `courses` (one query, unpaged) — the batched twin |
| 150 | /// of [`list_for_course`]: the catalogue page reads one query per page, not |
| 151 | /// one per course. Ids that name no course are simply absent from the result. |
| 152 | pub async |
| 153 | |
| 154 | |
| 155 | |
| 156 | |
| 157 | |
| 158 | |
| 159 | |
| 160 | |
| 161 | |
| 162 | |
| 163 | |
| 164 | |
| 165 | |
| 166 | |
| 167 | |
| 168 | |
| 169 | |
| 170 | |
| 171 | |
| 172 | |
| 173 | |
| 174 | |
| 175 | |
| 176 | |
| 177 | |
| 178 | |
| 179 | |
| 180 | |
| 181 | |
| 182 | |
| 183 | |
| 184 | /// Every instance `teacher` is assigned to (one query, unpaged) — the batched |
| 185 | /// replacement for [`list_for_teacher`]-then-[`list_for_course`]-per-course: |
| 186 | /// a reach read walks the assignment junction directly, so a teacher's |
| 187 | /// catalogue page costs one query, not one per taught course. A teacher |
| 188 | /// assigned to two sections of one course gets both rows; an id that names no |
| 189 | /// assignment is simply absent. |
| 190 | pub async |
| 191 | |
| 192 | |
| 193 | |
| 194 | |
| 195 | |
| 196 | |
| 197 | |
| 198 | |
| 199 | |
| 200 | |
| 201 | |
| 202 | |
| 203 | |
| 204 | |
| 205 | |
| 206 | |
| 207 | |
| 208 | |
| 209 | |
| 210 | |
| 211 | |
| 212 | |
| 213 | |
| 214 | |
| 215 | |
| 216 | |
| 217 | |
| 218 | |
| 219 | /// Load every instance behind `ids` (one query) — the join half of the reads |
| 220 | /// that already hold instance ids (a marks report's per-instance blocks). |
| 221 | pub async |
| 222 | |
| 223 | |
| 224 | |
| 225 | |
| 226 | |
| 227 | |
| 228 | |
| 229 | |
| 230 | |
| 231 | |
| 232 | |
| 233 | |
| 234 | |
| 235 | |
| 236 | |
| 237 | |
| 238 | |
| 239 | |
| 240 | |
| 241 | |
| 242 | |
| 243 | |
| 244 | |
| 245 | |
| 246 | |
| 247 | |
| 248 | |
| 249 | |
| 250 | |
| 251 | |
| 252 | |
| 253 | /// One instance, or `None` when the id names no row. |
| 254 | pub async |
| 255 | |
| 256 | |
| 257 | |
| 258 | |
| 259 | |
| 260 | |
| 261 | |
| 262 | |
| 263 | |
| 264 | |
| 265 | |
| 266 | |
| 267 | |
| 268 | |
| 269 | |
| 270 | |
| 271 | |
| 272 | |
| 273 | |
| 274 | |
| 275 | |
| 276 | |
| 277 | |
| 278 | /// The class this instance belongs to, or `None` when the id names no row — |
| 279 | /// the seam every instance-scoped route reads the section (and, through it, the |
| 280 | /// year) off. |
| 281 | pub async |
| 282 | |
| 283 | |
| 284 | |
| 285 | |
| 286 | |
| 287 | |
| 288 | |
| 289 | |
| 290 | |
| 291 | /// Set the instance's own policy overrides — the PATCH behind |
| 292 | /// `PATCH /instances/{id}`. Each `Some(_)` *sets* the column (a PATCH never |
| 293 | /// clears; clearing is [`clear_overrides`]'s job); `None` keeps what the |
| 294 | /// column holds. |
| 295 | /// |
| 296 | /// No counter moves and no compare-and-set is needed: every field is an |
| 297 | /// independent scalar, so two PATCHes touching different ones cannot revert |
| 298 | /// each other. `Err(NotFound)` when the instance is gone — the same answer |
| 299 | /// the caller's own read gives one instant earlier. |
| 300 | pub async |
| 301 | |
| 302 | |
| 303 | |
| 304 | |
| 305 | |
| 306 | |
| 307 | |
| 308 | |
| 309 | |
| 310 | |
| 311 | |
| 312 | |
| 313 | |
| 314 | |
| 315 | |
| 316 | |
| 317 | |
| 318 | |
| 319 | |
| 320 | |
| 321 | |
| 322 | |
| 323 | |
| 324 | |
| 325 | |
| 326 | |
| 327 | |
| 328 | |
| 329 | |
| 330 | |
| 331 | |
| 332 | |
| 333 | |
| 334 | |
| 335 | |
| 336 | |
| 337 | |
| 338 | |
| 339 | |
| 340 | |
| 341 | |
| 342 | |
| 343 | |
| 344 | |
| 345 | |
| 346 | |
| 347 | |
| 348 | |
| 349 | |
| 350 | |
| 351 | /// Clear the named overrides back to **inherit**: the scalars go `NULL` (the |
| 352 | /// offering's default, then the constants, apply again) and a set flag goes |
| 353 | /// back to `TRUE` (the offering's set is authoritative again — deleting the |
| 354 | /// section's own set rows rides the child-table lanes' reset). The empty |
| 355 | /// request is refused by the service before it gets here; a gone instance is |
| 356 | /// the usual 404. |
| 357 | /// |
| 358 | /// The whole reset is one statement: the named clears are judged on the row |
| 359 | /// as it is *at the write*, so a PATCH landing between the caller's read and |
| 360 | /// this write cannot be silently reverted field-by-field. |
| 361 | pub async |
| 362 | |
| 363 | |
| 364 | |
| 365 | |
| 366 | |
| 367 | |
| 368 | |
| 369 | |
| 370 | |
| 371 | |
| 372 | |
| 373 | |
| 374 | |
| 375 | |
| 376 | |
| 377 | |
| 378 | |
| 379 | |
| 380 | |
| 381 | |
| 382 | |
| 383 | |
| 384 | |
| 385 | |
| 386 | |
| 387 | |
| 388 | |
| 389 | |
| 390 | |
| 391 | |
| 392 | |
| 393 | |
| 394 | |
| 395 | |
| 396 | |
| 397 | |
| 398 | |
| 399 | |
| 400 | |
| 401 | |
| 402 | |
| 403 | |
| 404 | |
| 405 | |
| 406 | |
| 407 | |
| 408 | |
| 409 | |
| 410 | |
| 411 | |
| 412 |