backbone_support/presentation/dto/
service_level_priority_dto.rs1use serde::{Deserialize, Serialize};
9use uuid::Uuid;
10use chrono::{DateTime, Utc};
11
12#[cfg(feature = "openapi")]
13#[cfg(feature = "openapi")]
14use utoipa::ToSchema;
15
16#[cfg(feature = "validation")]
17use validator::Validate;
18
19use crate::domain::entity::ServiceLevelPriority;
20use crate::domain::entity::AuditMetadata;
21use crate::domain::entity::IssuePriority;
22
23#[derive(Debug, Clone, Deserialize)]
32#[cfg_attr(feature = "openapi", derive(ToSchema))]
33#[cfg_attr(feature = "validation", derive(Validate))]
34#[serde(rename_all = "camelCase")]
35pub struct CreateServiceLevelPriorityDto {
36 #[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
37 #[serde(alias = "sla_id")]
38 pub sla_id: Uuid,
39 pub priority: IssuePriority,
40 #[cfg_attr(feature = "openapi", schema(example = 42))]
41 #[serde(alias = "response_time_mins")]
42 pub response_time_mins: i32,
43 #[cfg_attr(feature = "openapi", schema(example = 42))]
44 #[serde(alias = "resolution_time_mins")]
45 pub resolution_time_mins: i32,
46}
47
48#[derive(Debug, Clone, Deserialize)]
57#[cfg_attr(feature = "openapi", derive(ToSchema))]
58#[cfg_attr(feature = "validation", derive(Validate))]
59#[serde(rename_all = "camelCase")]
60pub struct UpdateServiceLevelPriorityDto {
61 #[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
62 #[serde(alias = "sla_id")]
63 pub sla_id: Uuid,
64 pub priority: IssuePriority,
65 #[cfg_attr(feature = "openapi", schema(example = 42))]
66 #[serde(alias = "response_time_mins")]
67 pub response_time_mins: i32,
68 #[cfg_attr(feature = "openapi", schema(example = 42))]
69 #[serde(alias = "resolution_time_mins")]
70 pub resolution_time_mins: i32,
71}
72
73#[derive(Debug, Clone, Default, Deserialize)]
82#[cfg_attr(feature = "openapi", derive(ToSchema))]
83#[cfg_attr(feature = "validation", derive(Validate))]
84#[serde(rename_all = "camelCase")]
85pub struct PatchServiceLevelPriorityDto {
86 #[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
87 #[serde(skip_serializing_if = "Option::is_none", alias = "sla_id")]
88 pub sla_id: Option<Uuid>,
89 #[serde(skip_serializing_if = "Option::is_none")]
90 pub priority: Option<IssuePriority>,
91 #[cfg_attr(feature = "openapi", schema(example = 42))]
92 #[serde(skip_serializing_if = "Option::is_none", alias = "response_time_mins")]
93 pub response_time_mins: Option<i32>,
94 #[cfg_attr(feature = "openapi", schema(example = 42))]
95 #[serde(skip_serializing_if = "Option::is_none", alias = "resolution_time_mins")]
96 pub resolution_time_mins: Option<i32>,
97}
98
99impl PatchServiceLevelPriorityDto {
100 pub fn has_changes(&self) -> bool {
102 self.sla_id.is_some() || self.priority.is_some() || self.response_time_mins.is_some() || self.resolution_time_mins.is_some()
103 }
104}
105
106#[derive(Debug, Clone, Serialize)]
115#[cfg_attr(feature = "openapi", derive(ToSchema))]
116#[serde(rename_all = "camelCase")]
117pub struct ServiceLevelPriorityResponseDto {
118 #[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
119 pub id: Uuid,
120 #[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
121 pub sla_id: Uuid,
122 pub priority: IssuePriority,
123 #[cfg_attr(feature = "openapi", schema(example = 42))]
124 pub response_time_mins: i32,
125 #[cfg_attr(feature = "openapi", schema(example = 42))]
126 pub resolution_time_mins: i32,
127 pub metadata: AuditMetadata,
128}
129
130#[derive(Debug, Clone, Serialize)]
139#[cfg_attr(feature = "openapi", derive(ToSchema))]
140#[serde(rename_all = "camelCase")]
141pub struct ServiceLevelPriorityListResponseDto {
142 pub items: Vec<ServiceLevelPriorityResponseDto>,
144 pub total: u64,
146 pub page: u32,
148 pub per_page: u32,
150 pub total_pages: u32,
152 pub has_next: bool,
154 pub has_prev: bool,
156}
157
158impl ServiceLevelPriorityListResponseDto {
159 pub fn new(items: Vec<ServiceLevelPriorityResponseDto>, total: u64, page: u32, per_page: u32) -> Self {
161 let total_pages = if per_page > 0 {
162 ((total as f64) / (per_page as f64)).ceil() as u32
163 } else {
164 0
165 };
166 Self {
167 items,
168 total,
169 page,
170 per_page,
171 total_pages,
172 has_next: page < total_pages,
173 has_prev: page > 1,
174 }
175 }
176}
177
178#[derive(Debug, Clone, Serialize)]
180#[cfg_attr(feature = "openapi", derive(ToSchema))]
181#[serde(rename_all = "camelCase")]
182pub struct ServiceLevelPrioritySummaryDto {
183 pub id: Uuid,
184 pub sla_id: Uuid,
185 pub priority: IssuePriority,
186 pub response_time_mins: i32,
187 pub created_at: Option<DateTime<Utc>>,
188}
189
190impl From<ServiceLevelPriority> for ServiceLevelPriorityResponseDto {
195 fn from(entity: ServiceLevelPriority) -> Self {
196 Self {
197 id: entity.id,
198 sla_id: entity.sla_id,
199 priority: entity.priority,
200 response_time_mins: entity.response_time_mins,
201 resolution_time_mins: entity.resolution_time_mins,
202 metadata: entity.metadata,
203 }
204 }
205}
206
207impl From<ServiceLevelPriority> for ServiceLevelPrioritySummaryDto {
208 fn from(entity: ServiceLevelPriority) -> Self {
209 let created_at = backbone_core::PersistentEntity::created_at(&entity);
210 Self {
211 id: entity.id,
212 sla_id: entity.sla_id,
213 priority: entity.priority,
214 response_time_mins: entity.response_time_mins,
215 created_at,
216 }
217 }
218}
219
220impl From<CreateServiceLevelPriorityDto> for ServiceLevelPriority {
221 fn from(dto: CreateServiceLevelPriorityDto) -> Self {
222 Self {
223 id: Uuid::new_v4(),
224 sla_id: dto.sla_id,
225 priority: dto.priority,
226 response_time_mins: dto.response_time_mins,
227 resolution_time_mins: dto.resolution_time_mins,
228 metadata: AuditMetadata::default(),
229 }
230 }
231}
232
233impl From<&ServiceLevelPriority> for ServiceLevelPriorityResponseDto {
234 fn from(entity: &ServiceLevelPriority) -> Self {
235 Self {
236 id: entity.id.clone(),
237 sla_id: entity.sla_id.clone(),
238 priority: entity.priority.clone(),
239 response_time_mins: entity.response_time_mins.clone(),
240 resolution_time_mins: entity.resolution_time_mins.clone(),
241 metadata: entity.metadata.clone(),
242 }
243 }
244}
245
246impl backbone_core::FromCreateDto<CreateServiceLevelPriorityDto> for ServiceLevelPriority {
247 fn from_create_dto(dto: CreateServiceLevelPriorityDto) -> backbone_core::ServiceResult<Self> {
248 Ok(ServiceLevelPriority::from(dto))
249 }
250}
251
252impl backbone_core::ApplyUpdateDto<UpdateServiceLevelPriorityDto> for ServiceLevelPriority {
253 fn apply_update(mut self, dto: UpdateServiceLevelPriorityDto) -> backbone_core::ServiceResult<Self> {
254 self.sla_id = dto.sla_id;
255 self.priority = dto.priority;
256 self.response_time_mins = dto.response_time_mins;
257 self.resolution_time_mins = dto.resolution_time_mins;
258 Ok(self)
259 }
260}
261
262