Skip to main content

backbone_bucket/application/service/
processing_job_service.rs

1//! Application service for ProcessingJob 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 `processing_job_service_custom.rs` (preserved on regen).
7
8use backbone_core::GenericCrudService;
9
10use crate::presentation::dto::{CreateProcessingJobDto, UpdateProcessingJobDto};
11use crate::domain::entity::ProcessingJob;
12use crate::infrastructure::persistence::ProcessingJobRepository;
13
14/// Application service for ProcessingJob 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 `processing_job_service_custom.rs`:
21///
22/// ```rust,ignore
23/// pub struct ProcessingJobServiceCustom {
24///     inner: Arc<ProcessingJobService>,
25///     // add domain-specific dependencies here
26/// }
27/// ```
28pub type ProcessingJobService = GenericCrudService<
29    ProcessingJob,
30    CreateProcessingJobDto,
31    UpdateProcessingJobDto,
32    ProcessingJobRepository,
33>;
34
35/// The row rules the schema declares for ProcessingJob, checked against the row a create or
36/// update would store. The generated build attaches it to [`ProcessingJobService`]. Every rule
37/// runs in shadow: a break is logged under `backbone::write_guard` and the write goes ahead.
38pub struct ProcessingJobRowRules;
39
40#[async_trait::async_trait]
41impl backbone_core::write_guard::WriteGuard<ProcessingJob> for ProcessingJobRowRules {
42    async fn check(
43        &self,
44        ctx: &backbone_core::write_guard::WriteCtx<'_, ProcessingJob>,
45    ) -> backbone_core::write_guard::GuardOutcome {
46        use backbone_core::row_rule as r;
47        use backbone_core::violation::Violation;
48        use backbone_core::write_guard::{GuardOutcome, WriteKind};
49        let (create, update) = (ctx.kind == WriteKind::Create, ctx.kind == WriteKind::Update);
50        let Some(after) = ctx.after.filter(|_| create || update) else {
51            return GuardOutcome::allow();
52        };
53        let Ok(row) = serde_json::to_value(after) else {
54            return GuardOutcome::allow();
55        };
56        let row = &row;
57        let mut shadow = Vec::new();
58        // `priority_valid` (processing_job.hook.yaml:139)
59        if (create || update) && !r::holds(&r::and(r::ge(r::field(row, "priority"), r::Val::Num(0.0_f64)), r::le(r::field(row, "priority"), r::Val::Num(10.0_f64)))) {
60            shadow.push(Violation::new("priority", "invalid_priority", "Priority must be 0-10"));
61        }
62        // `cannot_modify_completed` (processing_job.hook.yaml:145)
63        if (update) && !r::holds(&r::ne(r::field(row, "status"), r::text("completed"))) {
64            shadow.push(Violation::new("status", "job_completed", "Cannot modify completed jobs"));
65        }
66        GuardOutcome { refuse: Vec::new(), shadow }
67    }
68}
69