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 `exam_audience` junction: which instances one exam is announced to. |
| 2 | //! |
| 3 | //! Every exam is *owned* by exactly one instance — the `class_course` column |
| 4 | //! on its own row — and [`crate::db::exam::insert_in`] writes that owner's |
| 5 | //! audience row in the same transaction as the exam. The rows beyond it are |
| 6 | //! the **shared exam**'s (D2): one exam announced to another section's instance, |
| 7 | //! sat and graded once, standing in every addressed instance's marks and |
| 8 | //! report card. Every exam read goes through this table |
| 9 | //! ([`crate::db::exam::list_for_class_course`] and the marks reports' joins), |
| 10 | //! so the audience set is the single answer to "which instances does this |
| 11 | //! exam belong to" and the owner column is only the join's tie-break. |
| 12 | //! |
| 13 | //! The owner's row is never removed from here: [`crate::service::exam`] |
| 14 | //! refuses that pair on both routes, and deleting the exam is what ends its |
| 15 | //! audience — [`crate::db::exam::delete`] and the instance sweep each clear |
| 16 | //! the rows in their own transaction. The audience a detach may *not* leave |
| 17 | //! behind is the one pointing at the detaching instance: an exam owned by |
| 18 | //! another instance would block the `class_course` delete with a `23503`, so |
| 19 | //! [`crate::db::course::sweep_instance_subtree`] clears both directions. |
| 20 | |
| 21 | use crate; |
| 22 | use crateClassCourseId; |
| 23 | use crateClassGroupId; |
| 24 | use crateCourseId; |
| 25 | use crateExamId; |
| 26 | use crateUserId; |
| 27 | use crateAppError; |
| 28 | |
| 29 | /// One audience row, resolved to what a client needs to name it: the |
| 30 | /// instance, the section it belongs to and the catalog course it teaches. |
| 31 | |
| 32 | |
| 33 | |
| 34 | |
| 35 | |
| 36 | |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | |
| 42 | |
| 43 | |
| 44 | |
| 45 | |
| 46 | |
| 47 | |
| 48 | |
| 49 | |
| 50 | |
| 51 | |
| 52 | |
| 53 | |
| 54 | |
| 55 | |
| 56 | /// Announce `exam` to `class_course`. An audience the exam already carries is |
| 57 | /// success, not a refusal: the announcement is idempotent, exactly like a |
| 58 | /// teacher assignment ([`crate::db::class_course_teacher::assign`]), and the |
| 59 | /// route answers the resulting set either way. |
| 60 | /// |
| 61 | /// Both foreign keys answer a gone parent with `NotFound`: an exam swept by a |
| 62 | /// concurrent detach and an instance that never existed are the same answer |
| 63 | /// to the caller, and neither may read as a `500`. |
| 64 | pub async |
| 65 | |
| 66 | |
| 67 | |
| 68 | |
| 69 | |
| 70 | |
| 71 | |
| 72 | |
| 73 | |
| 74 | |
| 75 | |
| 76 | |
| 77 | |
| 78 | |
| 79 | |
| 80 | |
| 81 | |
| 82 | |
| 83 | |
| 84 | /// Drop an audience row. `false` when the pair held none, so the web layer |
| 85 | /// can answer 404 instead of pretending it removed one — the shape |
| 86 | /// [`crate::db::class_course_teacher::unassign`] has. |
| 87 | pub async |
| 88 | |
| 89 | |
| 90 | |
| 91 | |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 | |
| 97 | |
| 98 | |
| 99 | |
| 100 | |
| 101 | |
| 102 | /// Every instance `exam` is announced to, in the order they were announced — |
| 103 | /// uuidv7 is creation order — the read behind `GET /exams/{id}/audience`. |
| 104 | pub async |
| 105 | |
| 106 | |
| 107 | |
| 108 | |
| 109 | |
| 110 | |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | |
| 116 | |
| 117 | |
| 118 | |
| 119 | |
| 120 | |
| 121 | /// The exams addressed to one instance — the reverse read, for a caller that |
| 122 | /// starts from the instance rather than the exam (`exam_audience`'s |
| 123 | /// `class_course` index is the side it walks). |
| 124 | pub async |
| 125 | |
| 126 | |
| 127 | |
| 128 | |
| 129 | |
| 130 | |
| 131 | |
| 132 | |
| 133 | |
| 134 | |
| 135 | |
| 136 | |
| 137 | |
| 138 | /// Whether `user` is enrolled in any instance `exam` is addressed to — the |
| 139 | /// owner included, its audience row always standing. |
| 140 | /// |
| 141 | /// The enrollment predicate the sitting and grading gates ask once one exam |
| 142 | /// can be announced to several instances (D2): for an exam nobody was |
| 143 | /// announced to this is the owner-only check those gates used to run, row for |
| 144 | /// row, and for a shared exam it admits the addressed sections' students — |
| 145 | /// who sit and are graded at their own instance exactly like the owner's. |
| 146 | pub async |
| 147 | |
| 148 | |
| 149 | |
| 150 | |
| 151 | |
| 152 | |
| 153 | |
| 154 | |
| 155 | |
| 156 | |
| 157 |