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 weekly plan surface: the timetable template's routes on both owners — |
| 2 | //! the grade-level offering (`/offerings/{id}/weekly-plan`, the office's |
| 3 | //! door) and the class×course instance (`/instances/{id}/weekly-plan`, the |
| 4 | //! D10 door), split into the two mount functions the router composes |
| 5 | //! (`offering_routes` under `/offerings`, `instance_routes` inside |
| 6 | //! `/instances`) so each carries its own module's gate. |
| 7 | //! |
| 8 | //! A slot is one weekday plus a minutes-past-midnight window (`1` = Monday |
| 9 | //! through `7` = Sunday, `540` = 09:00), and may carry an optional lesson |
| 10 | //! topic. Two slots of one owner may touch but never overlap (409 |
| 11 | //! `slot_overlap`); a plan holds at most |
| 12 | //! [`crate::constant::MAX_WEEKLY_SLOTS`] slots (409 `slot_cap`). |
| 13 | //! Writing any instance-side row flips `weekly_plan_inherited` to `false` in |
| 14 | //! the same statement, and `DELETE /instances/{id}/weekly-plan` (no slot id) |
| 15 | //! is the reset back to inherit — the resolved reads never merge the two |
| 16 | //! sets. |
| 17 | //! |
| 18 | //! **No scheduler** — but one explicit door: `POST |
| 19 | //! /instances/{id}/weekly-plan/materialize` expands the section's *resolved* |
| 20 | //! plan into dated `course_session` rows over a range, dry-run first and |
| 21 | //! bounded by the school's holiday calendar |
| 22 | //! ([`crate::service::course_session::materialize`]). Nothing generates |
| 23 | //! lessons on its own; a caller asks, and a second ask over the same range |
| 24 | //! writes nothing new. |
| 25 | |
| 26 | use Json; |
| 27 | use Path; |
| 28 | use StatusCode; |
| 29 | use ; |
| 30 | use ToSchema; |
| 31 | use OpenApiRouter; |
| 32 | use routes; |
| 33 | |
| 34 | use crateDatabase; |
| 35 | use cratezone_offset_minutes; |
| 36 | use crate; |
| 37 | use crate; |
| 38 | use crateSessionTopic; |
| 39 | use crateTimestamp; |
| 40 | use crate; |
| 41 | use crate; |
| 42 | use crateservice; |
| 43 | use crateAppState; |
| 44 | use crateState; |
| 45 | |
| 46 | use can_view_instance; |
| 47 | use |
| 48 | |
| 49 | |
| 50 | ; |
| 51 | |
| 52 | /// The route set mounted under `/offerings` (relative paths): the template |
| 53 | /// week's reads and the office's writes. |
| 54 | |
| 55 | |
| 56 | |
| 57 | |
| 58 | |
| 59 | |
| 60 | /// The instance-side half: mounted inside `/instances` — the section's |
| 61 | /// resolved plan, its override writes, and the reset. The two `DELETE`s stay |
| 62 | /// in separate `routes!` calls — one call may register each HTTP method only |
| 63 | /// once. |
| 64 | |
| 65 | |
| 66 | |
| 67 | |
| 68 | |
| 69 | |
| 70 | |
| 71 | |
| 72 | /// A weekly plan line the caller sent: the ISO weekday, the two |
| 73 | /// minutes-past-midnight bounds of the lesson window, and the optional topic |
| 74 | /// every lesson generated from it is stamped with. |
| 75 | |
| 76 | |
| 77 | |
| 78 | |
| 79 | |
| 80 | |
| 81 | |
| 82 | |
| 83 | |
| 84 | |
| 85 | |
| 86 | |
| 87 | |
| 88 | |
| 89 | |
| 90 | |
| 91 | |
| 92 | |
| 93 | |
| 94 | /// Public shape of one weekly plan slot. Times stay the minutes-past-midnight |
| 95 | /// form the request sent; `weekday` stays the integer (`1` = Monday). |
| 96 | |
| 97 | |
| 98 | |
| 99 | |
| 100 | |
| 101 | |
| 102 | |
| 103 | |
| 104 | |
| 105 | |
| 106 | |
| 107 | |
| 108 | |
| 109 | |
| 110 | |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | |
| 116 | |
| 117 | |
| 118 | |
| 119 | |
| 120 | |
| 121 | |
| 122 | /// The section's **resolved** weekly plan: whose rows are authoritative and |
| 123 | /// what they are — the offering's template week while |
| 124 | /// `weekly_plan_inherited` stands, the section's own rows (possibly empty) |
| 125 | /// once it overrode. Ordered weekday first, then start time. |
| 126 | |
| 127 | |
| 128 | |
| 129 | |
| 130 | |
| 131 | |
| 132 | |
| 133 | |
| 134 | async |
| 135 | |
| 136 | |
| 137 | |
| 138 | |
| 139 | |
| 140 | /// The instance a path id names, or a 404 — the read arm mirrors |
| 141 | /// [`super::instances`]'s. |
| 142 | async |
| 143 | |
| 144 | |
| 145 | |
| 146 | |
| 147 | |
| 148 | /// The body's slot, range-checked before anything is written: weekday and |
| 149 | /// minute bounds here, the non-empty window inside the domain `WeeklySlot`, |
| 150 | /// and the optional topic through its own newtype. |
| 151 | |
| 152 | |
| 153 | |
| 154 | |
| 155 | |
| 156 | |
| 157 | |
| 158 | |
| 159 | |
| 160 | |
| 161 | |
| 162 | |
| 163 | |
| 164 | |
| 165 | /// List the offering's template week — weekday first, then start time. Any |
| 166 | /// signed-in session, the same visibility as the offering read itself. |
| 167 | |
| 168 | |
| 169 | |
| 170 | |
| 171 | |
| 172 | |
| 173 | |
| 174 | |
| 175 | |
| 176 | |
| 177 | |
| 178 | |
| 179 | async |
| 180 | |
| 181 | |
| 182 | |
| 183 | |
| 184 | |
| 185 | |
| 186 | |
| 187 | |
| 188 | |
| 189 | /// Add one slot to the offering's template week. Manager+. Refused with 409 |
| 190 | /// `slot_overlap` when a template slot already occupies an intersecting |
| 191 | /// window on that weekday (an exact duplicate overlaps too), 409 `slot_cap` |
| 192 | /// when the week already holds the maximum. |
| 193 | |
| 194 | |
| 195 | |
| 196 | |
| 197 | |
| 198 | |
| 199 | |
| 200 | |
| 201 | |
| 202 | |
| 203 | |
| 204 | |
| 205 | |
| 206 | |
| 207 | |
| 208 | |
| 209 | |
| 210 | async |
| 211 | |
| 212 | |
| 213 | |
| 214 | |
| 215 | |
| 216 | |
| 217 | |
| 218 | |
| 219 | |
| 220 | |
| 221 | |
| 222 | |
| 223 | |
| 224 | |
| 225 | |
| 226 | |
| 227 | |
| 228 | |
| 229 | |
| 230 | /// Drop one slot of the offering's template week. Manager+. A slot of another |
| 231 | /// offering, or one already gone, is a 404. |
| 232 | |
| 233 | |
| 234 | |
| 235 | |
| 236 | |
| 237 | |
| 238 | |
| 239 | |
| 240 | |
| 241 | |
| 242 | |
| 243 | |
| 244 | |
| 245 | |
| 246 | |
| 247 | |
| 248 | async |
| 249 | |
| 250 | |
| 251 | : , |
| 252 | ) |
| 253 | |
| 254 | |
| 255 | |
| 256 | |
| 257 | |
| 258 | |
| 259 | |
| 260 | |
| 261 | |
| 262 | |
| 263 | /// The section's resolved weekly plan plus whose rows it is. Visible to the |
| 264 | /// same eyes as the instance read: enrolled students, its teachers, its |
| 265 | /// şube's homeroom teacher, and managers/admins. |
| 266 | |
| 267 | |
| 268 | |
| 269 | |
| 270 | |
| 271 | |
| 272 | |
| 273 | |
| 274 | |
| 275 | |
| 276 | |
| 277 | |
| 278 | |
| 279 | async |
| 280 | |
| 281 | |
| 282 | |
| 283 | |
| 284 | |
| 285 | |
| 286 | |
| 287 | |
| 288 | |
| 289 | |
| 290 | |
| 291 | |
| 292 | |
| 293 | |
| 294 | |
| 295 | |
| 296 | |
| 297 | /// Add one slot to the section's own week. Requires teacher+ and a right over |
| 298 | /// the instance; the write flips `weekly_plan_inherited` to `false` in the |
| 299 | /// same statement, so from here the section's own rows — not the offering's |
| 300 | /// template — are what every read resolves. Same overlap and cap refusals as |
| 301 | /// the offering side. |
| 302 | |
| 303 | |
| 304 | |
| 305 | |
| 306 | |
| 307 | |
| 308 | |
| 309 | |
| 310 | |
| 311 | |
| 312 | |
| 313 | |
| 314 | |
| 315 | |
| 316 | |
| 317 | |
| 318 | |
| 319 | async |
| 320 | |
| 321 | |
| 322 | |
| 323 | |
| 324 | |
| 325 | |
| 326 | |
| 327 | |
| 328 | |
| 329 | |
| 330 | |
| 331 | |
| 332 | |
| 333 | |
| 334 | |
| 335 | |
| 336 | |
| 337 | |
| 338 | |
| 339 | |
| 340 | |
| 341 | |
| 342 | /// Drop one slot of the section's own week. Requires teacher+ and a right |
| 343 | /// over the instance. The flag flip to `false` rides the delete in the same |
| 344 | /// statement — dropping the last own row leaves the section with an |
| 345 | /// authoritative *empty* plan, not a quiet return to the template |
| 346 | /// (`DELETE /{id}/weekly-plan` is the way back to inherit). A slot of another |
| 347 | /// instance, or one already gone, is a 404 that leaves the flag untouched. |
| 348 | |
| 349 | |
| 350 | |
| 351 | |
| 352 | |
| 353 | |
| 354 | |
| 355 | |
| 356 | |
| 357 | |
| 358 | |
| 359 | |
| 360 | |
| 361 | |
| 362 | |
| 363 | |
| 364 | |
| 365 | async |
| 366 | |
| 367 | |
| 368 | : , |
| 369 | ) |
| 370 | |
| 371 | |
| 372 | |
| 373 | |
| 374 | |
| 375 | |
| 376 | |
| 377 | |
| 378 | |
| 379 | |
| 380 | |
| 381 | |
| 382 | /// Reset the section's weekly plan to inherit — delete every slot of its own |
| 383 | /// week and flip `weekly_plan_inherited` back to `true` in one statement, so |
| 384 | /// the offering's template week is what every read resolves again. |
| 385 | /// Idempotent for a section that never overrode. |
| 386 | |
| 387 | |
| 388 | |
| 389 | |
| 390 | |
| 391 | |
| 392 | |
| 393 | |
| 394 | |
| 395 | |
| 396 | |
| 397 | |
| 398 | |
| 399 | |
| 400 | async |
| 401 | |
| 402 | |
| 403 | |
| 404 | |
| 405 | |
| 406 | |
| 407 | |
| 408 | |
| 409 | |
| 410 | |
| 411 | |
| 412 | // ---- materialize: the plan, made real ---------------------------------------- |
| 413 | |
| 414 | /// One materialize call: the range to cover, and whether to write. |
| 415 | |
| 416 | |
| 417 | |
| 418 | |
| 419 | |
| 420 | |
| 421 | |
| 422 | |
| 423 | |
| 424 | |
| 425 | |
| 426 | |
| 427 | |
| 428 | |
| 429 | |
| 430 | |
| 431 | |
| 432 | |
| 433 | |
| 434 | |
| 435 | /// One non-teaching day the range reached into. |
| 436 | |
| 437 | |
| 438 | |
| 439 | |
| 440 | |
| 441 | |
| 442 | |
| 443 | |
| 444 | |
| 445 | |
| 446 | /// What one materialize call did — or, on a dry run, would have done. |
| 447 | |
| 448 | |
| 449 | |
| 450 | |
| 451 | |
| 452 | |
| 453 | |
| 454 | |
| 455 | |
| 456 | |
| 457 | |
| 458 | |
| 459 | |
| 460 | |
| 461 | |
| 462 | |
| 463 | |
| 464 | |
| 465 | |
| 466 | |
| 467 | |
| 468 | |
| 469 | |
| 470 | |
| 471 | |
| 472 | |
| 473 | /// Expand this section's **resolved** weekly plan into dated lessons over |
| 474 | /// `from`–`to`. Requires teacher+ and a right over the instance (the same door |
| 475 | /// as adding a slot, since this writes lessons). |
| 476 | /// |
| 477 | /// Nothing is ever deleted or updated: the call is additive, and a second call |
| 478 | /// over the same range writes nothing (`UNIQUE (class_course, starts_at)`), so |
| 479 | /// retrying after a failure is safe. A weekday the plan has no slot for |
| 480 | /// produces nothing, and so does every day a holiday reaches into — those days |
| 481 | /// are named in `blocked`. Weekends are *not* special-cased: a school may run |
| 482 | /// Saturday, so only the plan and the calendar decide. |
| 483 | /// |
| 484 | /// The generated lesson's teacher is the instance's **first assigned** |
| 485 | /// teacher, and its topic is the slot's own topic, else the instance's |
| 486 | /// resolved course title, else the literal `"Ders"`. |
| 487 | |
| 488 | |
| 489 | |
| 490 | |
| 491 | |
| 492 | |
| 493 | |
| 494 | |
| 495 | |
| 496 | |
| 497 | |
| 498 | |
| 499 | |
| 500 | |
| 501 | |
| 502 | |
| 503 | |
| 504 | async |
| 505 | |
| 506 | |
| 507 | |
| 508 | |
| 509 | |
| 510 | |
| 511 | |
| 512 | |
| 513 | |
| 514 | |
| 515 | |
| 516 | |
| 517 | |
| 518 | |
| 519 | |
| 520 | |
| 521 | |
| 522 | |
| 523 | |
| 524 | |
| 525 | |
| 526 | |
| 527 | |
| 528 | |
| 529 | |
| 530 | |
| 531 | |
| 532 | |
| 533 | |
| 534 | |
| 535 | |
| 536 | |
| 537 | |
| 538 | |
| 539 | |
| 540 | |
| 541 | |
| 542 | |
| 543 | |
| 544 | |
| 545 | |
| 546 | |
| 547 | |
| 548 | |
| 549 | |
| 550 | |
| 551 | |
| 552 | |
| 553 | |
| 554 | |
| 555 | |
| 556 | |
| 557 | |
| 558 | |
| 559 | |
| 560 | |
| 561 | |
| 562 | |
| 563 | |
| 564 | |
| 565 | |
| 566 | |
| 567 | |
| 568 | |
| 569 | |
| 570 | |
| 571 | |
| 572 | |
| 573 | |
| 574 |