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 `academic_year` table: the row mint, the paged calendar listing, the |
| 2 | //! field-scoped PATCH whose `WHERE` re-checks the merged range, and the 0/0 |
| 3 | //! delete guard. |
| 4 | //! |
| 5 | //! The year is the top of the academic calendar (D3): a section belongs to a |
| 6 | //! year and a term ([`crate::db::term`]) is a grading slice inside it. Its two |
| 7 | //! counters are the delete guard — a year that still carries a section or a |
| 8 | //! term is refused outright, because dropping it silently would strand the |
| 9 | //! year's structure. The rollover that reads and writes the sections lives one |
| 10 | //! layer up ([`crate::service::academic_year::rollover`]). |
| 11 | |
| 12 | use Json; |
| 13 | |
| 14 | use crateDatabase; |
| 15 | use cratePagedList; |
| 16 | use crate |
| 17 | |
| 18 | ; |
| 19 | use crateTimestamp; |
| 20 | use crateUserId; |
| 21 | use crateAppError; |
| 22 | |
| 23 | /// Mint one year. The creator is a foreign key: a gone account is the same |
| 24 | /// `NotFound` the web layer's own read answers with, never an orphan row. |
| 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 | |
| 59 | |
| 60 | |
| 61 | |
| 62 | |
| 63 | |
| 64 | |
| 65 | |
| 66 | pub async |
| 67 | |
| 68 | |
| 69 | |
| 70 | |
| 71 | |
| 72 | |
| 73 | |
| 74 | |
| 75 | |
| 76 | |
| 77 | |
| 78 | |
| 79 | |
| 80 | |
| 81 | |
| 82 | /// Every year, newest first — the calendar is small by nature. |
| 83 | pub async |
| 84 | |
| 85 | |
| 86 | |
| 87 | |
| 88 | |
| 89 | |
| 90 | |
| 91 | |
| 92 | |
| 93 | /// Write only the fields the PATCH carried — `None` means the request omitted |
| 94 | /// it, so the column keeps the value it holds rather than being re-stated from |
| 95 | /// the snapshot the handler read. Every column here is non-clearable, so |
| 96 | /// `COALESCE` is the whole rule: absent = keep. |
| 97 | /// |
| 98 | /// The merged range is re-checked by the `WHERE` (`ends_at > starts_at` on the |
| 99 | /// values this write will leave behind), so two PATCHes each moving one end |
| 100 | /// cannot commit an inverted year between them. `Err(NotFound)` when the row |
| 101 | /// is gone. |
| 102 | pub async |
| 103 | |
| 104 | |
| 105 | |
| 106 | |
| 107 | |
| 108 | |
| 109 | |
| 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 | |
| 140 | |
| 141 | |
| 142 | |
| 143 | |
| 144 | |
| 145 | |
| 146 | |
| 147 | |
| 148 | |
| 149 | |
| 150 | |
| 151 | |
| 152 | |
| 153 | /// Archive the year — the stamp that turns the whole year read-only. Idempotent |
| 154 | /// by construction: the `WHERE` only matches an open row, so a repeat archive |
| 155 | /// writes nothing and the *original* stamp stands — the year is never re-dated |
| 156 | /// by a double click. `None` says this write landed on nothing: the row was |
| 157 | /// already archived, or it is gone. The store does not tell those apart; the |
| 158 | /// caller holds the row it read (the service layer) and only a race pays for |
| 159 | /// the read that would. |
| 160 | pub async |
| 161 | |
| 162 | |
| 163 | |
| 164 | |
| 165 | |
| 166 | |
| 167 | |
| 168 | |
| 169 | |
| 170 | |
| 171 | |
| 172 | |
| 173 | |
| 174 | |
| 175 | |
| 176 | |
| 177 | |
| 178 | /// Delete the year, but only while no section and no term links it — nothing |
| 179 | /// here unlinks or cascades. `false` = refused, nothing was written. |
| 180 | /// |
| 181 | /// Both counts are read off the year's own row, so the check and the delete |
| 182 | /// are one conditional write on one record: a class or term write racing this |
| 183 | /// either claims first (and the delete is refused) or finds the row gone (and |
| 184 | /// is refused itself). The referencing foreign keys (`class_group.year`, |
| 185 | /// `term.year`, both `NO ACTION`) are the backstop behind the counters, not a |
| 186 | /// second guard. The `Err(NotFound)` keeps the answer a concurrent *delete* |
| 187 | /// used to get. |
| 188 | pub async |
| 189 | |
| 190 | |
| 191 | |
| 192 | |
| 193 | |
| 194 | |
| 195 | |
| 196 | |
| 197 | |
| 198 | |
| 199 | |
| 200 | |
| 201 | |
| 202 | |
| 203 | |
| 204 | |
| 205 | |
| 206 | |
| 207 | /// A real academic year for the fixtures of the tables that hang off one: a |
| 208 | /// term ([`crate::db::term::a_test_term`]) and, through it, every exam. Minted |
| 209 | /// per call — the name is unique — with a creator that is a real `app_user` |
| 210 | /// row, because `creator` is a foreign key. |
| 211 | |
| 212 | pub async |
| 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 |