backbone_support/application/service/
service_level_priority_service.rs1use backbone_core::GenericCrudService;
9
10use crate::presentation::dto::{CreateServiceLevelPriorityDto, UpdateServiceLevelPriorityDto};
11use crate::domain::entity::ServiceLevelPriority;
12use crate::infrastructure::persistence::ServiceLevelPriorityRepository;
13
14pub type ServiceLevelPriorityService = GenericCrudService<
29 ServiceLevelPriority,
30 CreateServiceLevelPriorityDto,
31 UpdateServiceLevelPriorityDto,
32 ServiceLevelPriorityRepository,
33>;
34
35pub struct ServiceLevelPriorityRowRules;
40
41#[async_trait::async_trait]
42impl backbone_core::write_guard::WriteGuard<ServiceLevelPriority> for ServiceLevelPriorityRowRules {
43 async fn check(
44 &self,
45 ctx: &backbone_core::write_guard::WriteCtx<'_, ServiceLevelPriority>,
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 if (create || (update && r::changed(old.as_ref(), row, &["sla_id"]))) && !r::holds(&r::and(r::is_not_null(r::field(row, "sla_id")), r::not(r::is_empty(r::trim(r::field(row, "sla_id")))))) {
63 refuse.push(Violation::new("sla_id", "required", "sla_id is required"));
64 }
65 if (create || (update && r::changed(old.as_ref(), row, &["response_time_mins"]))) && !r::holds(&r::ge(r::field(row, "response_time_mins"), r::Val::Num(0.0_f64))) {
67 shadow.push(Violation::new("response_time_mins", "non_negative", "response_time_mins must not be negative"));
68 }
69 if (create || (update && r::changed(old.as_ref(), row, &["resolution_time_mins"]))) && !r::holds(&r::ge(r::field(row, "resolution_time_mins"), r::Val::Num(0.0_f64))) {
71 shadow.push(Violation::new("resolution_time_mins", "non_negative", "resolution_time_mins must not be negative"));
72 }
73 GuardOutcome { refuse, shadow }
74 }
75}
76