forge
Explore
Log in

Don't you dare go Hollow

hezarfen_backend

Clone
★ 0

0 watching0 forksRust8.3 MiB6d68754Ahmet Kaan Gümüş2 months ago566 commits

fee_plan.rs53 lines, 1.9 KiBHistoryRawDownload
1//! Fee-plan doors for the web layer. Every write here is a single guarded
2//! statement in [`crate::db::fee_plan`] — the assigned-plan freeze is the
3//! store's own, decided as the write lands — so this module is thin
4//! pass-throughs; the manager+ gate is the web layer's extractor.
5
6use crate::database::Database;
7use crate::db::fee_plan;
8use crate::domain::fee_plan::{FeePlan, FeePlanId, FeePlanName, Installment};
9use crate::domain::user::UserId;
10use crate::error::AppError;
11
12/// Write a fee plan: a name and the installments it is paid in. Creating one
13/// bills nobody — assigning it does.
14pub async fn create(
15 db: &Database,
16 name: FeePlanName,
17 installments: Vec<Installment>,
18 created_by: &UserId,
19) -> Result<FeePlan, AppError> {
20 fee_plan::create(db, name, installments, created_by).await
21}
22
23/// The plan, for callers that only inspect it.
24pub async fn read(db: &Database, id: &FeePlanId) -> Result<Option<FeePlan>, AppError> {
25 fee_plan::read(db, id).await
26}
27
28/// Every plan, newest first.
29pub async fn list_all(
30 db: &Database,
31 limit: Option<i64>,
32 offset: i64,
33) -> Result<(Vec<FeePlan>, i64), AppError> {
34 fee_plan::list_all(db, limit, offset).await
35}
36
37/// Edit a plan's name and/or schedule. `Err(Conflict)` = refused, nothing was
38/// written: somebody is already on the plan (and `Err(NotFound)` = the plan
39/// is gone, so the refusal is not "assigned" but "deleted").
40pub async fn update(
41 db: &Database,
42 plan: FeePlan,
43 name: Option<FeePlanName>,
44 installments: Option<Vec<Installment>>,
45) -> Result<FeePlan, AppError> {
46 fee_plan::update(db, plan, name, installments).await
47}
48
49/// Delete the plan while nobody is on it. `false` = refused: somebody is on
50/// it, and a school's financial history keeps its references.
51pub async fn delete(db: &Database, plan: FeePlan) -> Result<bool, AppError> {
52 fee_plan::delete(db, plan).await
53}