hezarfen_backend
Clone
https://git.tahinli.com/Hezarfen/hezarfen_backend.git
0 watching0 forksRust8.3 MiB6d68754Ahmet Kaan Gümüş2 months ago566 commits
| 1 | //! The `work_entry` table: the open-slot check-in/check-out pair, the |
| 2 | //! newest-first log, and manager corrections guarded by the stored order. |
| 3 | //! |
| 4 | //! "At most one open stint per staff member" is the database's own rule here: |
| 5 | //! the partial unique index `work_entry_open` covers only rows whose |
| 6 | //! `check_out` is NULL, so a second check-in is a 23505 (mapped to the |
| 7 | //! check-in conflict below) and a check-out is one conditional `UPDATE` — |
| 8 | //! zero rows means there was no open stint to close. The old |
| 9 | //! take-and-re-file dance existed only to free the deterministic open id; |
| 10 | //! with the index, closing the stint *is* freeing the slot. |
| 11 | |
| 12 | use crateDatabase; |
| 13 | use crateFieldUpdate; |
| 14 | use crateTimestamp; |
| 15 | use crateUserId; |
| 16 | use crate; |
| 17 | use crateAppError; |
| 18 | |
| 19 | /// The row as the table spells it (`app_user` column), one step from the |
| 20 | /// domain struct (whose field is `user`). |
| 21 | |
| 22 | |
| 23 | |
| 24 | |
| 25 | |
| 26 | |
| 27 | |
| 28 | |
| 29 | |
| 30 | |
| 31 | |
| 32 | |
| 33 | |
| 34 | |
| 35 | |
| 36 | |
| 37 | |
| 38 | |
| 39 | /// Open a stint for `user`, stamped with the server clock. The |
| 40 | /// `work_entry_open` partial unique index makes this atomic: if an open |
| 41 | /// entry already exists the insert is refused and the caller gets the |
| 42 | /// conflict — two racing check-ins can never create two open rows or reset |
| 43 | /// a running clock. One statement, one verdict, no retry loop. |
| 44 | pub async |
| 45 | |
| 46 | |
| 47 | |
| 48 | |
| 49 | |
| 50 | |
| 51 | |
| 52 | |
| 53 | |
| 54 | |
| 55 | |
| 56 | |
| 57 | |
| 58 | |
| 59 | |
| 60 | |
| 61 | |
| 62 | |
| 63 | |
| 64 | |
| 65 | |
| 66 | /// Close `user`'s open stint: one conditional `UPDATE` takes it and stamps |
| 67 | /// `check_out`, which also frees the open slot for the next check-in (the |
| 68 | /// partial unique index only covers rows with a NULL `check_out`). Zero |
| 69 | /// rows = no open stint, the caller's conflict. Of two racing check-outs |
| 70 | /// exactly one receives the row — the statement takes the row's lock and |
| 71 | /// the loser re-evaluates against the winner's committed state. |
| 72 | pub async |
| 73 | |
| 74 | |
| 75 | |
| 76 | |
| 77 | |
| 78 | |
| 79 | |
| 80 | |
| 81 | |
| 82 | |
| 83 | |
| 84 | |
| 85 | |
| 86 | |
| 87 | |
| 88 | |
| 89 | pub async |
| 90 | |
| 91 | |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 | |
| 97 | |
| 98 | |
| 99 | |
| 100 | /// Every stint of `user`, newest first — the open one (if any) included. |
| 101 | /// Ordered by `check_in DESC`; the minted `id` breaks ties between two |
| 102 | /// stints sharing a `check_in` (uuid v7 sorts in mint order, which is what |
| 103 | /// keeps offset paging from skipping a row). |
| 104 | pub async |
| 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 | |
| 154 | |
| 155 | |
| 156 | |
| 157 | |
| 158 | |
| 159 | |
| 160 | |
| 161 | |
| 162 | |
| 163 | /// Persist corrected instants (manager fix-ups on closed entries; the web |
| 164 | /// layer validates ordering and rejects open entries). |
| 165 | /// `None` = the correction left that instant out, so it is not written at |
| 166 | /// all — the stint's `user` and `check_in`/`check_out` stamps are never |
| 167 | /// replayed from a struct the handler read before its validation awaits. |
| 168 | /// `check_out` is never cleared here: an open stint is refused upstream, so |
| 169 | /// "absent" and "null" both mean keep. |
| 170 | pub async |
| 171 | |
| 172 | |
| 173 | |
| 174 | |
| 175 | |
| 176 | |
| 177 | |
| 178 | |
| 179 | |
| 180 | |
| 181 | |
| 182 | |
| 183 | |
| 184 | |
| 185 | |
| 186 | |
| 187 | pub async |
| 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 |