hezarfen_backend
Clone
https://git.tahinli.com/archive/hezarfen_backend.git
0 watching0 forksRust8.3 MiB6d68754Ahmet Kaan Gümüş2 months ago566 commits
| 1 | //! Course-session workflows: who may teach a lesson (the teacher-resolution |
| 2 | //! gate), and the doors the web layer takes for every session read and |
| 3 | //! write. The queries live in [`crate::db::course_session`]; the |
| 4 | //! timetable's wire shaping and the course-rights checks stay in the web |
| 5 | //! layer. |
| 6 | //! |
| 7 | //! The one workflow with a plan behind it is [`materialize`]: it expands an |
| 8 | //! instance's *resolved* weekly plan ([`crate::service::weekly_slot`]) into |
| 9 | //! dated lessons over a range, bounded by the school-wide holiday calendar |
| 10 | //! ([`crate::service::holiday::blocked_days`]). It is an explicit route's |
| 11 | //! work, not a scheduler: nothing generates lessons on its own. |
| 12 | |
| 13 | use crate; |
| 14 | use crate; |
| 15 | use crate; |
| 16 | use cratecalendar; |
| 17 | use crate; |
| 18 | use crate; |
| 19 | use crateHolidayName; |
| 20 | use crateRole; |
| 21 | use crateTimestamp; |
| 22 | use crate; |
| 23 | use crate; |
| 24 | |
| 25 | /// Resolve who a session's teacher should be: the caller when `teacher_id` is |
| 26 | /// omitted (or names them), otherwise the referenced user — who must exist and |
| 27 | /// hold the `teacher` role or higher (a student cannot teach a lesson). |
| 28 | /// |
| 29 | /// Scheduling hands the named person the session's teaching seat, so the |
| 30 | /// floor is checked on the *live* role here rather than at the web layer: |
| 31 | /// every future roll-call right derives from this column, and a stale |
| 32 | /// `teacher_id` in a request body must fail with the same 400 no matter |
| 33 | /// which route named it. |
| 34 | pub async |
| 35 | |
| 36 | |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | |
| 42 | |
| 43 | |
| 44 | |
| 45 | |
| 46 | |
| 47 | |
| 48 | |
| 49 | |
| 50 | |
| 51 | |
| 52 | |
| 53 | |
| 54 | |
| 55 | |
| 56 | |
| 57 | |
| 58 | |
| 59 | /// Schedule a lesson on `class_course` — one dated occurrence of the instance, |
| 60 | /// which is what a roll call hangs off. |
| 61 | pub async |
| 62 | |
| 63 | |
| 64 | |
| 65 | |
| 66 | |
| 67 | |
| 68 | |
| 69 | |
| 70 | |
| 71 | |
| 72 | pub async |
| 73 | |
| 74 | |
| 75 | |
| 76 | /// An instance's sessions, most recent lesson first — the timetable read, |
| 77 | /// unbounded by any schedule window. |
| 78 | pub async |
| 79 | |
| 80 | |
| 81 | |
| 82 | |
| 83 | |
| 84 | |
| 85 | |
| 86 | |
| 87 | /// The same timetable read narrowed to a half-open `[starts_after, |
| 88 | /// starts_before)` on `starts_at` — a calendar month is |
| 89 | /// `[month_start, next_month_start)`. The page and the count share the one |
| 90 | /// SQL `WHERE`; the order does not flip. |
| 91 | pub async |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 | |
| 97 | |
| 98 | |
| 99 | |
| 100 | |
| 101 | |
| 102 | |
| 103 | |
| 104 | |
| 105 | |
| 106 | |
| 107 | |
| 108 | |
| 109 | |
| 110 | /// Only what the request carried is written: an omitted field (`None`) is |
| 111 | /// not stored at all, so a concurrent PATCH of that field survives. The |
| 112 | /// range consistency re-check rides in the UPDATE's own `WHERE`, so the |
| 113 | /// caller holds nothing across its read and this write. |
| 114 | pub async |
| 115 | |
| 116 | |
| 117 | |
| 118 | |
| 119 | |
| 120 | |
| 121 | |
| 122 | |
| 123 | |
| 124 | |
| 125 | /// Delete the session and sweep its roll-call rows in one transaction. |
| 126 | pub async |
| 127 | |
| 128 | |
| 129 | |
| 130 | /// One non-teaching day the generator refused to schedule on: the calendar |
| 131 | /// day in the school's zone, and the holiday that reaches into it. |
| 132 | |
| 133 | |
| 134 | |
| 135 | |
| 136 | |
| 137 | |
| 138 | /// What one [`materialize`] call did — or, on a dry run, would have done. |
| 139 | /// |
| 140 | /// `created` carries the rows the database actually inserted (empty on a dry |
| 141 | /// run), so a lesson a concurrent writer already put at the same instant is |
| 142 | /// reported as skipped, never counted. `candidates` is the size the range |
| 143 | /// asked for, `slots` the resolved plan's size, and `blocked` one entry per |
| 144 | /// holiday-blocked *day*. |
| 145 | |
| 146 | |
| 147 | |
| 148 | |
| 149 | |
| 150 | |
| 151 | |
| 152 | |
| 153 | |
| 154 | |
| 155 | |
| 156 | |
| 157 | /// Expand `instance`'s resolved weekly plan into dated lessons over |
| 158 | /// `[from, to]` (inclusive instants), one lesson per plan slot per matching |
| 159 | /// weekday, skipping the days a holiday reaches into and the instants the |
| 160 | /// section already holds a lesson at. |
| 161 | /// |
| 162 | /// `apply == false` is a dry run: it reads, decides, and writes nothing. |
| 163 | /// `apply == true` writes the collected rows in this transaction and returns |
| 164 | /// exactly the rows that landed — the whole feature is additive, nothing is |
| 165 | /// ever deleted or updated, and a second run over the same range is a no-op |
| 166 | /// (`UNIQUE (class_course, starts_at)`). Weekends are not special-cased: a |
| 167 | /// school may run Saturday, so only the plan and the holidays decide. |
| 168 | /// |
| 169 | /// `offset_minutes` is the school's zone offset |
| 170 | /// ([`crate::domain::calendar::zone_offset_minutes`]); the range's instants |
| 171 | /// name *school* days, and each lesson lands at its slot's minute of that |
| 172 | /// local day. |
| 173 | /// |
| 174 | /// Refusals: an archived year, an empty plan (409 |
| 175 | /// `instance_has_no_weekly_plan`), no assigned teacher (409 |
| 176 | /// `instance_has_no_teacher`, the lesson's teacher is the instance's first |
| 177 | /// assigned one), a range longer than a year or one that would mint more than |
| 178 | /// [`MAX_MATERIALIZE_SESSIONS`] lessons (400), and a gone instance |
| 179 | /// ([`AppError::NotFound`]). |
| 180 | pub async |
| 181 | |
| 182 | |
| 183 | |
| 184 | |
| 185 | |
| 186 | |
| 187 | |
| 188 | |
| 189 | |
| 190 | |
| 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 | |
| 220 | |
| 221 | |
| 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 | |
| 254 | |
| 255 | |
| 256 | |
| 257 | |
| 258 | |
| 259 | |
| 260 | |
| 261 | |
| 262 | |
| 263 | |
| 264 | |
| 265 | |
| 266 | |
| 267 | |
| 268 | |
| 269 | |
| 270 | |
| 271 | |
| 272 | |
| 273 | |
| 274 | |
| 275 | |
| 276 | |
| 277 | |
| 278 | |
| 279 | |
| 280 | |
| 281 | |
| 282 | |
| 283 | |
| 284 | |
| 285 | |
| 286 | |
| 287 | |
| 288 | |
| 289 | |
| 290 | |
| 291 | |
| 292 | |
| 293 | |
| 294 | |
| 295 | |
| 296 | |
| 297 | |
| 298 | |
| 299 | |
| 300 | |
| 301 | |
| 302 | |
| 303 | |
| 304 | |
| 305 | |
| 306 | |
| 307 | |
| 308 | |
| 309 | |
| 310 | |
| 311 | |
| 312 | |
| 313 | |
| 314 | |
| 315 | |
| 316 | |
| 317 | |
| 318 | |
| 319 | |
| 320 | |
| 321 | |
| 322 | |
| 323 | |
| 324 |