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 `fee_plan_assignment` table: the claim that places a student on a plan |
| 2 | //! (and freezes the plan), plus the reads over placements. The billing the |
| 3 | //! claim triggers lives in [`crate::service::fee_plan_assignment::assign`]; |
| 4 | //! the ledger appends in [`crate::db::payment_ledger`]. |
| 5 | |
| 6 | use crateDatabase; |
| 7 | use crate; |
| 8 | use cratePagedList; |
| 9 | use crateFeePlanId; |
| 10 | use crate; |
| 11 | use crateTimestamp; |
| 12 | use crateUserId; |
| 13 | use crateAppError; |
| 14 | |
| 15 | pub async |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 | |
| 21 | |
| 22 | |
| 23 | |
| 24 | |
| 25 | |
| 26 | |
| 27 | |
| 28 | |
| 29 | |
| 30 | |
| 31 | /// Place one (plan, student) assignment and claim the plan's assignment |
| 32 | /// refcount in the **same statement** — that increment is what makes the plan |
| 33 | /// un-editable and un-deletable ([`crate::db::fee_plan::update`]/[`delete`]), |
| 34 | /// and it has to be indivisible from the row it counts, or an edit could slip |
| 35 | /// between the two. The claim recipe ([`crate::db::cap`]'s |
| 36 | /// claim-and-create): a conditional `UPDATE` on the plan row seats the count, |
| 37 | /// the `INSERT` rides `WHERE EXISTS` on that seat, and one statement decides. |
| 38 | /// |
| 39 | /// The verdict maps as the guard layer promises: 23505 on |
| 40 | /// `fee_plan_assignment_plan` → [`Claimed::Duplicate`] (someone assigned this |
| 41 | /// pair first; their row is the answer); zero rows → [`Claimed::Full`] (the |
| 42 | /// counter is uncapped, so the only miss is a plan a concurrent delete |
| 43 | /// already removed); one row → [`Claimed::Made`]. |
| 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 | |
| 67 | |
| 68 | |
| 69 | |
| 70 | |
| 71 | |
| 72 | |
| 73 | |
| 74 | |
| 75 | |
| 76 | |
| 77 | |
| 78 | |
| 79 | |
| 80 | |
| 81 | |
| 82 | |
| 83 | /// Who is on this plan, newest first. |
| 84 | pub async |
| 85 | |
| 86 | |
| 87 | |
| 88 | |
| 89 | |
| 90 | |
| 91 | |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 | |
| 97 | |
| 98 | |
| 99 | /// Is anybody on this plan? A scan, and no longer a guard: the edit and |
| 100 | /// delete guards read the plan's own refcount, which no concurrent assign |
| 101 | /// can be behind. Kept because a *test* asserting the rows and the counter |
| 102 | /// agree is the only thing that would catch the counter drifting. |
| 103 | pub async |
| 104 | |
| 105 | |
| 106 | |
| 107 | |
| 108 | |
| 109 | |
| 110 | |
| 111 | |
| 112 | |
| 113 | /// Which plans a student is on — one student may hold several. |
| 114 | pub async |
| 115 | |
| 116 | |
| 117 | |
| 118 | |
| 119 | |
| 120 | |
| 121 | |
| 122 | |
| 123 | |
| 124 | |
| 125 | |
| 126 | |
| 127 |