Skip to main content

backbone_integrations/application/service/
integration_event_service.rs

1//! Application service for IntegrationEvent 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 `integration_event_service_custom.rs` (preserved on regen).
7
8use backbone_core::GenericCrudService;
9
10use crate::presentation::dto::{CreateIntegrationEventDto, UpdateIntegrationEventDto};
11use crate::domain::entity::IntegrationEvent;
12use crate::infrastructure::persistence::IntegrationEventRepository;
13
14/// Application service for IntegrationEvent 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 `integration_event_service_custom.rs`:
21///
22/// ```rust,ignore
23/// pub struct IntegrationEventServiceCustom {
24///     inner: Arc<IntegrationEventService>,
25///     // add domain-specific dependencies here
26/// }
27/// ```
28pub type IntegrationEventService = GenericCrudService<
29    IntegrationEvent,
30    CreateIntegrationEventDto,
31    UpdateIntegrationEventDto,
32    IntegrationEventRepository,
33>;
34
35/// The rules the schema declares for IntegrationEvent, checked against the row a create or update
36/// would store. The generated build attaches it to [`IntegrationEventService`]. 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 IntegrationEventRowRules;
40
41#[async_trait::async_trait]
42impl backbone_core::write_guard::WriteGuard<IntegrationEvent> for IntegrationEventRowRules {
43    async fn check(
44        &self,
45        ctx: &backbone_core::write_guard::WriteCtx<'_, IntegrationEvent>,
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        // `connector_id_required` (@required on IntegrationEvent.connector_id)
62        if (create || (update && r::changed(old.as_ref(), row, &["connector_id"]))) && !r::holds(&r::and(r::is_not_null(r::field(row, "connector_id")), r::not(r::is_empty(r::trim(r::field(row, "connector_id")))))) {
63            refuse.push(Violation::new("connector_id", "required", "connector_id is required"));
64        }
65        // `event_type_required` (@required on IntegrationEvent.event_type)
66        if (create || (update && r::changed(old.as_ref(), row, &["event_type"]))) && !r::holds(&r::and(r::is_not_null(r::field(row, "event_type")), r::not(r::is_empty(r::trim(r::field(row, "event_type")))))) {
67            refuse.push(Violation::new("event_type", "required", "event_type is required"));
68        }
69        // `event_type_max_length` (@length(max=80) on IntegrationEvent.event_type)
70        if (create || (update && r::changed(old.as_ref(), row, &["event_type"]))) && !r::holds(&r::le(r::length(r::field(row, "event_type")), r::Val::Num(80.0_f64))) {
71            refuse.push(Violation::new("event_type", "max_length", "event_type must be at most 80 characters").with_param("max", 80_i64));
72        }
73        // `external_id_required` (@required on IntegrationEvent.external_id)
74        if (create || (update && r::changed(old.as_ref(), row, &["external_id"]))) && !r::holds(&r::and(r::is_not_null(r::field(row, "external_id")), r::not(r::is_empty(r::trim(r::field(row, "external_id")))))) {
75            refuse.push(Violation::new("external_id", "required", "external_id is required"));
76        }
77        // `external_id_max_length` (@length(max=200) on IntegrationEvent.external_id)
78        if (create || (update && r::changed(old.as_ref(), row, &["external_id"]))) && !r::holds(&r::le(r::length(r::field(row, "external_id")), r::Val::Num(200.0_f64))) {
79            refuse.push(Violation::new("external_id", "max_length", "external_id must be at most 200 characters").with_param("max", 200_i64));
80        }
81        // `business_key_required` (@required on IntegrationEvent.business_key)
82        if (create || (update && r::changed(old.as_ref(), row, &["business_key"]))) && !r::holds(&r::and(r::is_not_null(r::field(row, "business_key")), r::not(r::is_empty(r::trim(r::field(row, "business_key")))))) {
83            refuse.push(Violation::new("business_key", "required", "business_key is required"));
84        }
85        // `business_key_max_length` (@length(max=200) on IntegrationEvent.business_key)
86        if (create || (update && r::changed(old.as_ref(), row, &["business_key"]))) && !r::holds(&r::le(r::length(r::field(row, "business_key")), r::Val::Num(200.0_f64))) {
87            refuse.push(Violation::new("business_key", "max_length", "business_key must be at most 200 characters").with_param("max", 200_i64));
88        }
89        // `payload_required` (@required on IntegrationEvent.payload)
90        if (create || (update && r::changed(old.as_ref(), row, &["payload"]))) && !r::holds(&r::and(r::is_not_null(r::field(row, "payload")), r::not(r::is_empty(r::trim(r::field(row, "payload")))))) {
91            refuse.push(Violation::new("payload", "required", "payload is required"));
92        }
93        // `payload_max_length` (@length(max=20000) on IntegrationEvent.payload)
94        if (create || (update && r::changed(old.as_ref(), row, &["payload"]))) && !r::holds(&r::le(r::length(r::field(row, "payload")), r::Val::Num(20000.0_f64))) {
95            refuse.push(Violation::new("payload", "max_length", "payload must be at most 20000 characters").with_param("max", 20000_i64));
96        }
97        // `mapped_ref_type_max_length` (@length(max=60) on IntegrationEvent.mapped_ref_type)
98        if (create || (update && r::changed(old.as_ref(), row, &["mapped_ref_type"]))) && !r::holds(&r::le(r::length(r::field(row, "mapped_ref_type")), r::Val::Num(60.0_f64))) {
99            refuse.push(Violation::new("mapped_ref_type", "max_length", "mapped_ref_type must be at most 60 characters").with_param("max", 60_i64));
100        }
101        // `error_detail_max_length` (@length(max=1000) on IntegrationEvent.error_detail)
102        if (create || (update && r::changed(old.as_ref(), row, &["error_detail"]))) && !r::holds(&r::le(r::length(r::field(row, "error_detail")), r::Val::Num(1000.0_f64))) {
103            refuse.push(Violation::new("error_detail", "max_length", "error_detail must be at most 1000 characters").with_param("max", 1000_i64));
104        }
105        GuardOutcome { refuse, shadow }
106    }
107}
108