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 kitchen's workflows: publishing and unpublishing menus, and every |
| 2 | //! dish write. The queries live in [`crate::db::menu`] and |
| 3 | //! [`crate::db::menu_dish`]; the row shapes and the date/slot/capacity |
| 4 | //! rules in [`crate::domain::menu`] and [`crate::domain::menu_dish`]. |
| 5 | //! |
| 6 | //! **No process-wide lock guards this domain.** The dish cap |
| 7 | //! (`MAX_DISHES_PER_MENU`) used to be a count-then-write pair only a |
| 8 | //! process mutex could make safe; it is now one guarded statement — the |
| 9 | //! menu row is taken `FOR NO KEY UPDATE` inside the dish write's own |
| 10 | //! transaction and the `INSERT … WHERE count(*) < cap` runs behind that |
| 11 | //! lock, so two racing writers serialize on the row the database owns. |
| 12 | //! Every dish write moves the menu's revision in that same transaction, and |
| 13 | //! a booking claims its seat at the revision it priced itself against. |
| 14 | |
| 15 | use crateMAX_DISHES_PER_MENU; |
| 16 | use crateDatabase; |
| 17 | use crate; |
| 18 | use crate; |
| 19 | use crate |
| 20 | |
| 21 | ; |
| 22 | use crateUserId; |
| 23 | use crateAppError; |
| 24 | |
| 25 | /// Publish a menu for one day and meal slot. The caller has validated the |
| 26 | /// date (a real calendar day, not already over), the slot (one the school |
| 27 | /// serves) and the capacity; the day+slot duplicate refusal is decided by |
| 28 | /// the store ([`menu::create`]). |
| 29 | pub async |
| 30 | |
| 31 | |
| 32 | |
| 33 | |
| 34 | |
| 35 | |
| 36 | |
| 37 | |
| 38 | |
| 39 | /// The menu, for callers that only inspect it — the web layer's handlers |
| 40 | /// read through here. |
| 41 | pub async |
| 42 | |
| 43 | |
| 44 | |
| 45 | /// Menus, newest day first, within inclusive `YYYY-MM-DD` bounds. `slot`, |
| 46 | /// when given, narrows to menus published under that exact snapshotted |
| 47 | /// slot text. |
| 48 | pub async |
| 49 | |
| 50 | |
| 51 | |
| 52 | |
| 53 | |
| 54 | |
| 55 | |
| 56 | |
| 57 | |
| 58 | |
| 59 | /// Change a menu's seat cap; `None` keeps it, `Some(None)` clears it. |
| 60 | pub async |
| 61 | |
| 62 | |
| 63 | |
| 64 | |
| 65 | |
| 66 | |
| 67 | |
| 68 | /// Unpublish a menu, sweeping its dishes and attendance marks in the same |
| 69 | /// transaction; refused while a seat is still held. |
| 70 | pub async |
| 71 | |
| 72 | |
| 73 | |
| 74 | /// Add a dish to a menu, under the dish cap. |
| 75 | /// |
| 76 | /// The cap is the database's to enforce, not this process's: the write |
| 77 | /// locks the menu row `FOR NO KEY UPDATE` and its `INSERT` carries a |
| 78 | /// `count(*) < cap` guard, so a writer that queued behind a concurrent one |
| 79 | /// re-counts after the lock and is refused (`409`) instead of overfilling |
| 80 | /// — the count and the insert are one decision, with no window a second |
| 81 | /// writer can slip through. |
| 82 | /// |
| 83 | /// The *price* needs no lock — a dish write moves the menu's revision, and |
| 84 | /// a booking claims its seat at the revision it priced itself against. |
| 85 | pub async |
| 86 | |
| 87 | |
| 88 | |
| 89 | |
| 90 | |
| 91 | |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 | |
| 97 | |
| 98 | |
| 99 | |
| 100 | |
| 101 | |
| 102 | |
| 103 | |
| 104 | |
| 105 | /// One dish, for callers that only inspect it. |
| 106 | pub async |
| 107 | |
| 108 | |
| 109 | |
| 110 | /// Every dish on one menu, in the order they were added. |
| 111 | pub async |
| 112 | |
| 113 | |
| 114 | |
| 115 | /// Dishes for a whole page of menus in one round trip. |
| 116 | pub async |
| 117 | |
| 118 | |
| 119 | |
| 120 | |
| 121 | |
| 122 | |
| 123 | /// Edit a dish. Only what the request carried is written. |
| 124 | pub async |
| 125 | |
| 126 | |
| 127 | |
| 128 | |
| 129 | |
| 130 | |
| 131 | |
| 132 | |
| 133 | |
| 134 | |
| 135 | /// Remove a dish from its menu. |
| 136 | pub async |
| 137 | |
| 138 |