Skip to main content

backbone_pos/application/service/
pos_table_service.rs

1//! Application service for PosTable entities
2//!
3//! Generated by metaphor-schema. Do not edit manually.
4//!
5//! Type alias over `GenericCrudService` — all CRUD logic lives in backbone-core.
6//! For custom behaviour, create `pos_table_service_custom.rs` (preserved on regen).
7
8use backbone_core::GenericCrudService;
9
10use crate::presentation::dto::{CreatePosTableDto, UpdatePosTableDto};
11use crate::domain::entity::PosTable;
12use crate::infrastructure::persistence::PosTableRepository;
13
14/// Application service for PosTable entities.
15///
16/// All 12 standard CRUD operations (list, create, get, update, patch,
17/// soft_delete, restore, empty_trash, bulk_create, upsert, find_by_id,
18/// list_deleted) are provided by `GenericCrudService`.
19///
20/// Custom extensions go in `pos_table_service_custom.rs`:
21///
22/// ```rust,ignore
23/// pub struct PosTableServiceCustom {
24///     inner: Arc<PosTableService>,
25///     // add domain-specific dependencies here
26/// }
27/// ```
28pub type PosTableService = GenericCrudService<
29    PosTable,
30    CreatePosTableDto,
31    UpdatePosTableDto,
32    PosTableRepository,
33>;
34
35/// The rules the schema declares for PosTable, checked against the row a create or update
36/// would store. The generated build attaches it to [`PosTableService`]. A refusing rule's
37/// break answers 422; a rule in shadow is logged under `backbone::write_guard` and the
38/// write goes ahead.
39pub struct PosTableRowRules;
40
41#[async_trait::async_trait]
42impl backbone_core::write_guard::WriteGuard<PosTable> for PosTableRowRules {
43    async fn check(
44        &self,
45        ctx: &backbone_core::write_guard::WriteCtx<'_, PosTable>,
46    ) -> backbone_core::write_guard::GuardOutcome {
47        use backbone_core::row_rule as r;
48        use backbone_core::violation::Violation;
49        use backbone_core::write_guard::{GuardOutcome, WriteKind};
50        let (create, update) = (ctx.kind == WriteKind::Create, ctx.kind == WriteKind::Update);
51        let Some(after) = ctx.after.filter(|_| create || update) else {
52            return GuardOutcome::allow();
53        };
54        let Ok(row) = serde_json::to_value(after) else {
55            return GuardOutcome::allow();
56        };
57        let row = &row;
58        let old = ctx.before.and_then(|b| serde_json::to_value(b).ok());
59        let shadow = Vec::new();
60        let mut refuse = Vec::new();
61        // `pos_floor_plan_id_required` (@required on PosTable.pos_floor_plan_id)
62        if (create || (update && r::changed(old.as_ref(), row, &["pos_floor_plan_id"]))) && !r::holds(&r::and(r::is_not_null(r::field(row, "pos_floor_plan_id")), r::not(r::is_empty(r::trim(r::field(row, "pos_floor_plan_id")))))) {
63            refuse.push(Violation::new("pos_floor_plan_id", "required", "pos_floor_plan_id is required"));
64        }
65        // `name_max_length` (@max(140) on PosTable.name)
66        if (create || (update && r::changed(old.as_ref(), row, &["name"]))) && !r::holds(&r::le(r::length(r::field(row, "name")), r::Val::Num(140.0_f64))) {
67            refuse.push(Violation::new("name", "max_length", "name must be at most 140 characters").with_param("max", 140_i64));
68        }
69        // `shape_max_length` (@max(30) on PosTable.shape)
70        if (create || (update && r::changed(old.as_ref(), row, &["shape"]))) && !r::holds(&r::le(r::length(r::field(row, "shape")), r::Val::Num(30.0_f64))) {
71            refuse.push(Violation::new("shape", "max_length", "shape must be at most 30 characters").with_param("max", 30_i64));
72        }
73        GuardOutcome { refuse, shadow }
74    }
75}
76