hezarfen_backend
Clone
https://git.tahinli.com/archive/hezarfen_backend.git
0 watching0 forksRust8.3 MiBaf331ecAhmet Kaan Gümüş2 months ago451 commits
| 1 | //! The `answer_image` table: the drawing upsert that names the blob it |
| 2 | //! replaces from inside its own transaction, the per-sitting and per-exam |
| 3 | //! reads, and the sweeps the retake and cascades use. The row's pure half — |
| 4 | //! ids and the fresh-blob-name constructor — lives in |
| 5 | //! [`crate::domain::answer_image`]; the blob bytes stay the web layer's. |
| 6 | |
| 7 | use PgConnection; |
| 8 | |
| 9 | use crate; |
| 10 | use crateAnswerImage; |
| 11 | use crateCourseId; |
| 12 | use crateExamId; |
| 13 | use crateExamQuestionId; |
| 14 | use crateFileContentType; |
| 15 | use crateUserId; |
| 16 | use crateAppError; |
| 17 | |
| 18 | /// Create or replace the student's drawing for the question — the natural |
| 19 | /// (question, user, seq) primary key makes this the whole "one drawing per |
| 20 | /// student per question per sitting" story — handing back what it stored |
| 21 | /// plus the blob name it replaced, for the caller to take off disk. |
| 22 | /// |
| 23 | /// The replaced name is read *inside this transaction*, not by the caller |
| 24 | /// in front of it: two uploads to one (question, user, seq) both write this |
| 25 | /// row, so they contend and the loser re-reads the winner's blob name, |
| 26 | /// where two pre-reads both saw the *old* blob and left the loser's fresh |
| 27 | /// one on disk with nothing pointing at it. Same shape as |
| 28 | /// [`crate::db::question_image::upsert`]. |
| 29 | /// |
| 30 | /// `NotFound` = the exam is gone, and the drawing was *not* written. The |
| 31 | /// write locks the exam row before upserting, in this one transaction, so |
| 32 | /// the exam's existence is something this write *locks* rather than |
| 33 | /// something a gate read a moment earlier: a bare upsert landing after |
| 34 | /// [`delete`](crate::db::exam::delete) removed the exam but before it |
| 35 | /// committed was swept by nothing — its `DELETE answer_image WHERE exam` |
| 36 | /// ran on a snapshot predating this row — and both sides reported success. |
| 37 | /// That stranded the blob as well as the row: `delete_exam` collects the |
| 38 | /// names to unlink *before* it calls the delete, so bytes written after |
| 39 | /// that snapshot stay on disk forever. Locking the key the delete removes |
| 40 | /// serializes the pair — this is the shape |
| 41 | /// [`crate::db::exam_answer::save`] takes for the text half of the same |
| 42 | /// answer sheet, and for the same reason. |
| 43 | pub async |
| 44 | |
| 45 | |
| 46 | |
| 47 | |
| 48 | |
| 49 | |
| 50 | /// The locked exam-row probe plus the upsert, on one connection. |
| 51 | pub async |
| 52 | |
| 53 | |
| 54 | |
| 55 | |
| 56 | |
| 57 | |
| 58 | |
| 59 | |
| 60 | |
| 61 | |
| 62 | |
| 63 | |
| 64 | |
| 65 | |
| 66 | |
| 67 | |
| 68 | |
| 69 | |
| 70 | |
| 71 | |
| 72 | |
| 73 | |
| 74 | |
| 75 | |
| 76 | |
| 77 | |
| 78 | |
| 79 | |
| 80 | |
| 81 | |
| 82 | |
| 83 | |
| 84 | |
| 85 | |
| 86 | |
| 87 | |
| 88 | |
| 89 | |
| 90 | |
| 91 | |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 | |
| 97 | /// The student's drawing for one question in one sitting, if any. |
| 98 | pub async |
| 99 | |
| 100 | |
| 101 | |
| 102 | |
| 103 | |
| 104 | |
| 105 | |
| 106 | |
| 107 | |
| 108 | |
| 109 | |
| 110 | |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | |
| 116 | |
| 117 | |
| 118 | |
| 119 | /// Every answer drawing of the exam — one query for the exam-delete cascade. |
| 120 | pub async |
| 121 | |
| 122 | |
| 123 | |
| 124 | |
| 125 | |
| 126 | |
| 127 | |
| 128 | |
| 129 | |
| 130 | |
| 131 | |
| 132 | |
| 133 | /// One student's answer drawings for a single sitting — the parallel to |
| 134 | /// [`crate::db::exam_answer::list_for_exam_user`], feeding |
| 135 | /// the sitting/grading answer-image maps for that attempt's `seq`. |
| 136 | pub async |
| 137 | |
| 138 | |
| 139 | |
| 140 | |
| 141 | |
| 142 | |
| 143 | |
| 144 | |
| 145 | |
| 146 | |
| 147 | |
| 148 | |
| 149 | |
| 150 | |
| 151 | |
| 152 | |
| 153 | |
| 154 | |
| 155 | |
| 156 | /// The distinct sittings (`seq`, ascending) this student has any answer |
| 157 | /// drawing for at this exam — the history index behind a per-attempt view. |
| 158 | pub async |
| 159 | |
| 160 | |
| 161 | |
| 162 | |
| 163 | |
| 164 | |
| 165 | |
| 166 | |
| 167 | |
| 168 | |
| 169 | |
| 170 | |
| 171 | |
| 172 | |
| 173 | |
| 174 | /// The blob names behind every answer drawing of every exam of `course` — |
| 175 | /// collected *before* the course-delete cascade wipes the rows. |
| 176 | pub async |
| 177 | |
| 178 | |
| 179 | |
| 180 | |
| 181 | |
| 182 | |
| 183 | |
| 184 | |
| 185 | |
| 186 | |
| 187 | |
| 188 | |
| 189 | |
| 190 | pub async |
| 191 | |
| 192 | |
| 193 | |
| 194 | |
| 195 | |
| 196 | |
| 197 | |
| 198 | |
| 199 | |
| 200 | |
| 201 | |
| 202 | |
| 203 | |
| 204 | |
| 205 | |
| 206 | /// Drop one student's answer drawings across an exam — a retake starts from |
| 207 | /// a blank sheet. Rows only; the caller GCs the blobs. The retake path |
| 208 | /// itself wipes nothing: a retake's rows live at their own `seq`, and this |
| 209 | /// is the standalone mirror of |
| 210 | /// [`crate::db::exam_answer::delete_for_exam_user`]. |
| 211 | pub async |
| 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 | |
| 325 | |
| 326 | |
| 327 | |
| 328 |