hezarfen_backend
Clone
https://git.tahinli.com/archive/hezarfen_backend.git
0 watching0 forksRust8.3 MiB6d68754Ahmet Kaan Gümüş2 months ago566 commits
| 1 | use crateState; |
| 2 | use Json; |
| 3 | use ; |
| 4 | use StatusCode; |
| 5 | use ; |
| 6 | use ; |
| 7 | use OpenApiRouter; |
| 8 | use routes; |
| 9 | |
| 10 | use crateMAX_POMODORO_LABEL_LEN; |
| 11 | use cratePomodoroSession; |
| 12 | use crateRole; |
| 13 | use crate; |
| 14 | use crate; |
| 15 | use crateensure_can_observe; |
| 16 | use cratepomodoro; |
| 17 | use crateAppState; |
| 18 | use cratevalidate_optional; |
| 19 | |
| 20 | use ; |
| 21 | |
| 22 | |
| 23 | |
| 24 | |
| 25 | |
| 26 | |
| 27 | |
| 28 | |
| 29 | |
| 30 | /// A 403 unless `user` is a student — the pomodoro timer is the students' |
| 31 | /// study tool (staff time-keeping is the work log). Only `start` is gated: |
| 32 | /// finishing merely closes a session that only a student could have opened, |
| 33 | /// so a mid-session promotion still gets its last stint on the record. |
| 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 | |
| 67 | |
| 68 | |
| 69 | |
| 70 | |
| 71 | |
| 72 | |
| 73 | |
| 74 | |
| 75 | |
| 76 | |
| 77 | |
| 78 | |
| 79 | |
| 80 | |
| 81 | /// The standard `{items, total, limit, offset}` page envelope over the |
| 82 | /// sessions, plus the unpaged focus total — spelled out (not `Page<T>`) so the |
| 83 | /// extra field rides inside the same flat object. |
| 84 | |
| 85 | |
| 86 | |
| 87 | |
| 88 | |
| 89 | |
| 90 | |
| 91 | |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 | |
| 97 | |
| 98 | |
| 99 | |
| 100 | |
| 101 | |
| 102 | |
| 103 | |
| 104 | |
| 105 | |
| 106 | |
| 107 | |
| 108 | |
| 109 | |
| 110 | |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | /// The optional body names the stint: `{"label": "math"}` stores what the |
| 116 | /// student called it, trimmed, and the label then rides every response that |
| 117 | /// carries the session. A blank label starts an unnamed stint and an |
| 118 | /// over-long one is `400`; no body at all is exactly the old no-label start. |
| 119 | |
| 120 | |
| 121 | |
| 122 | |
| 123 | |
| 124 | |
| 125 | |
| 126 | |
| 127 | /// Start a pomodoro focus session. Students only. The instant is stamped by |
| 128 | /// the server clock — clients never supply it. Always succeeds for a student: |
| 129 | /// a dangling unfinished session (the browser died mid-timer) is discarded |
| 130 | /// and replaced, so there is no way to lock yourself out of starting. The |
| 131 | /// frontend runs the visible countdown and the break rhythm; the backend |
| 132 | /// records only the focus stint. The body is optional and names the stint: |
| 133 | /// a `label` rides the response and every log it lists in — a blank or |
| 134 | /// absent body starts an unnamed stint, an over-long label is `400`. |
| 135 | |
| 136 | |
| 137 | |
| 138 | |
| 139 | |
| 140 | |
| 141 | |
| 142 | |
| 143 | |
| 144 | |
| 145 | |
| 146 | |
| 147 | |
| 148 | |
| 149 | async |
| 150 | |
| 151 | |
| 152 | |
| 153 | |
| 154 | |
| 155 | |
| 156 | |
| 157 | |
| 158 | |
| 159 | |
| 160 | |
| 161 | |
| 162 | |
| 163 | |
| 164 | |
| 165 | |
| 166 | |
| 167 | |
| 168 | |
| 169 | /// Finish the running pomodoro session, closing it with a server-stamped |
| 170 | /// instant (`409` when nothing is running); answers `counted` — whether it |
| 171 | /// moved the badge counters (ran at least `pomodoro.min_counted_ms`, within |
| 172 | /// that UTC day's `pomodoro.max_counted_per_day`). |
| 173 | /// |
| 174 | /// The counters `counted` speaks for are the lifetime pomodoro ones — the |
| 175 | /// badges and the study streak read those. Both bounds are published on |
| 176 | /// `GET /limits`; the day bucket rolls at midnight UTC. A stint that counts |
| 177 | /// for nothing is still |
| 178 | /// recorded, still listed, and still sums into `total_focus_ms` — only the |
| 179 | /// badge counters are held to the rule, because finishing is self-service and a |
| 180 | /// counter moved once per round-trip is farmable. |
| 181 | |
| 182 | |
| 183 | |
| 184 | |
| 185 | |
| 186 | |
| 187 | |
| 188 | |
| 189 | |
| 190 | |
| 191 | |
| 192 | async |
| 193 | |
| 194 | |
| 195 | |
| 196 | |
| 197 | |
| 198 | |
| 199 | |
| 200 | /// The optional `?from=&to=` window over the log. Both bounds are UTC unix |
| 201 | /// milliseconds and half-open — `from` inclusive, `to` exclusive, so |
| 202 | /// adjacent windows tile without overlap — and independent: each present |
| 203 | /// bound narrows from its own end. Absent, the log is untouched. |
| 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 | /// The caller's own pomodoro log, newest first — the running session (if any) |
| 232 | /// included (`finished_at: null`) — plus `total_focus_ms`, the unpaged sum of |
| 233 | /// finished-session durations. Paged via `?limit=&offset=` (omit `limit` for |
| 234 | /// the whole log). |
| 235 | /// |
| 236 | /// `from`/`to` (unix milliseconds) narrow the log to sessions that started in |
| 237 | /// the half-open window `[from, to)` — both optional, AND-ed when both are |
| 238 | /// given, negative values a `400`. The window bounds the page, `total` and |
| 239 | /// `total_focus_ms` alike: the focus total is the sum over the same filtered |
| 240 | /// set the page reads, and with neither bound the response is the |
| 241 | /// whole-history log, unchanged. |
| 242 | |
| 243 | |
| 244 | |
| 245 | |
| 246 | |
| 247 | |
| 248 | |
| 249 | |
| 250 | |
| 251 | |
| 252 | |
| 253 | |
| 254 | async |
| 255 | |
| 256 | |
| 257 | |
| 258 | |
| 259 | |
| 260 | |
| 261 | |
| 262 | |
| 263 | |
| 264 | |
| 265 | |
| 266 | /// A student's pomodoro log, newest first, with `total_focus_ms` — the same |
| 267 | /// shape as `/me`. Requires teacher+ (study oversight), or a parent tied to |
| 268 | /// the target student. Paged via `?limit=&offset=`. |
| 269 | /// |
| 270 | /// Like `/me`, the optional `from`/`to` window (unix milliseconds, the |
| 271 | /// half-open `[from, to)`) narrows the log — page, `total` and |
| 272 | /// `total_focus_ms` together — and leaves the observation rules untouched: a |
| 273 | /// caller who may not read the log cannot read a window of it either. |
| 274 | |
| 275 | |
| 276 | |
| 277 | |
| 278 | |
| 279 | |
| 280 | |
| 281 | |
| 282 | |
| 283 | |
| 284 | |
| 285 | |
| 286 | |
| 287 | |
| 288 | async |
| 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 | |
| 329 | |
| 330 | |
| 331 | |
| 332 | |
| 333 | |
| 334 | |
| 335 | |
| 336 | |
| 337 | |
| 338 | |
| 339 | |
| 340 | |
| 341 | |
| 342 | |
| 343 | |
| 344 | |
| 345 | |
| 346 | |
| 347 | |
| 348 | |
| 349 | |
| 350 | |
| 351 | |
| 352 | |
| 353 | |
| 354 | |
| 355 | |
| 356 | |
| 357 | |
| 358 | |
| 359 | |
| 360 | |
| 361 | |
| 362 | |
| 363 | |
| 364 |