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 `class_course_teacher` junction: who teaches one instance. |
| 2 | //! |
| 3 | //! D6 moved teacher assignment off the catalog course and onto the instance — |
| 4 | //! two sections teaching the same course may legitimately have different |
| 5 | //! teachers — so this is the table every instance-membership gate reads |
| 6 | //! ([`crate::service::class_course::ensure_instance_teacher`]) and the one the |
| 7 | //! demotion sweep strips ([`crate::db::user::set_role_cascade`]). |
| 8 | //! |
| 9 | //! The shape is the `course_teacher` junction's, keyed on the instance: |
| 10 | //! assignment is an idempotent `INSERT` whose `(class_course, teacher)` key |
| 11 | //! answers a duplicate with `DO NOTHING`, so two requests naming the same |
| 12 | //! teacher at once land one row. |
| 13 | |
| 14 | use crate; |
| 15 | use crate; |
| 16 | use crateUserId; |
| 17 | use crateAppError; |
| 18 | |
| 19 | use HashMap; |
| 20 | |
| 21 | /// Assign `teacher` to teach this instance. `false` when they already did |
| 22 | /// (assignment is idempotent, so a repeat is a no-op rather than an error); |
| 23 | /// `Err(NotFound)` when the instance is gone — the same answer the caller's |
| 24 | /// own read gives one instant earlier. |
| 25 | pub async |
| 26 | |
| 27 | |
| 28 | |
| 29 | |
| 30 | |
| 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 | |
| 57 | |
| 58 | /// Drop `teacher` from this instance. `false` when they were not assigned to |
| 59 | /// it, so the web layer can answer 404 instead of pretending it removed |
| 60 | /// someone. |
| 61 | pub async |
| 62 | |
| 63 | |
| 64 | |
| 65 | |
| 66 | |
| 67 | |
| 68 | |
| 69 | |
| 70 | |
| 71 | |
| 72 | |
| 73 | |
| 74 | |
| 75 | |
| 76 | /// Strip `user` from every instance they were assigned to — the sweep for a |
| 77 | /// user demoted below `teacher`, who may no longer run anything. |
| 78 | pub async |
| 79 | |
| 80 | |
| 81 | |
| 82 | |
| 83 | |
| 84 | |
| 85 | |
| 86 | |
| 87 | |
| 88 | /// The teachers of one instance, by uuid — the read behind a single |
| 89 | /// `/instances/{id}` response. |
| 90 | pub async |
| 91 | |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 | |
| 97 | |
| 98 | |
| 99 | |
| 100 | |
| 101 | |
| 102 | |
| 103 | |
| 104 | /// Assemble `(instance, teachers)` pairs out of a batch of instance reads: |
| 105 | /// one `class_course_teacher` query for the whole batch, so a page of `n` |
| 106 | /// instances costs one extra statement rather than `n`. An instance nobody is |
| 107 | /// assigned to reads an empty list, the shape |
| 108 | /// [`crate::db::course`]'s old `into_courses` gave a course. |
| 109 | pub async |
| 110 | |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | |
| 116 | |
| 117 | |
| 118 | |
| 119 | |
| 120 | |
| 121 | |
| 122 | |
| 123 | |
| 124 | |
| 125 | |
| 126 | |
| 127 | |
| 128 | |
| 129 | |
| 130 | |
| 131 | |
| 132 | |
| 133 | |
| 134 | |
| 135 | |
| 136 | |
| 137 | |
| 138 | |
| 139 |