Skip to main content

backbone_pos/application/service/
pos_opening_entry_service.rs

1//! Application service for PosOpeningEntry 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_opening_entry_service_custom.rs` (preserved on regen).
7
8use backbone_core::GenericCrudService;
9
10use crate::presentation::dto::{CreatePosOpeningEntryDto, UpdatePosOpeningEntryDto};
11use crate::domain::entity::PosOpeningEntry;
12use crate::infrastructure::persistence::PosOpeningEntryRepository;
13
14/// Application service for PosOpeningEntry 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_opening_entry_service_custom.rs`:
21///
22/// ```rust,ignore
23/// pub struct PosOpeningEntryServiceCustom {
24///     inner: Arc<PosOpeningEntryService>,
25///     // add domain-specific dependencies here
26/// }
27/// ```
28pub type PosOpeningEntryService = GenericCrudService<
29    PosOpeningEntry,
30    CreatePosOpeningEntryDto,
31    UpdatePosOpeningEntryDto,
32    PosOpeningEntryRepository,
33>;
34
35/// The rules the schema declares for PosOpeningEntry, checked against the row a create or update
36/// would store. The generated build attaches it to [`PosOpeningEntryService`]. 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 PosOpeningEntryRowRules;
40
41#[async_trait::async_trait]
42impl backbone_core::write_guard::WriteGuard<PosOpeningEntry> for PosOpeningEntryRowRules {
43    async fn check(
44        &self,
45        ctx: &backbone_core::write_guard::WriteCtx<'_, PosOpeningEntry>,
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 mut shadow = Vec::new();
60        let mut refuse = Vec::new();
61        // `status` belongs to a state machine: only its verbs move it
62        if update && ctx.transition.is_none() && r::changed(old.as_ref(), row, &["status"]) {
63            shadow.push(Violation::new("status", "state_field_verbs_only", "the state field moves only through its verbs"));
64        }
65        // `pos_profile_id_required` (@required on PosOpeningEntry.pos_profile_id)
66        if (create || (update && r::changed(old.as_ref(), row, &["pos_profile_id"]))) && !r::holds(&r::and(r::is_not_null(r::field(row, "pos_profile_id")), r::not(r::is_empty(r::trim(r::field(row, "pos_profile_id")))))) {
67            refuse.push(Violation::new("pos_profile_id", "required", "pos_profile_id is required"));
68        }
69        // `cashier_party_id_required` (@required on PosOpeningEntry.cashier_party_id)
70        if (create || (update && r::changed(old.as_ref(), row, &["cashier_party_id"]))) && !r::holds(&r::and(r::is_not_null(r::field(row, "cashier_party_id")), r::not(r::is_empty(r::trim(r::field(row, "cashier_party_id")))))) {
71            refuse.push(Violation::new("cashier_party_id", "required", "cashier_party_id is required"));
72        }
73        GuardOutcome { refuse, shadow }
74    }
75}
76