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
16use crate::domain::entity::ServiceLevelPriority;
17use crate::domain::entity::AuditMetadata;
18use crate::domain::entity::IssuePriority;
19
20#[derive(Debug, Clone, Deserialize)]
29#[cfg_attr(feature = "openapi", derive(ToSchema))]
30#[serde(rename_all = "camelCase")]
31pub struct CreateServiceLevelPriorityDto {
32 #[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
33 #[serde(alias = "sla_id")]
34 pub sla_id: Uuid,
35 pub priority: IssuePriority,
36 #[cfg_attr(feature = "openapi", schema(example = 42))]
37 #[serde(alias = "response_time_mins")]
38 pub response_time_mins: i32,
39 #[cfg_attr(feature = "openapi", schema(example = 42))]
40 #[serde(alias = "resolution_time_mins")]
41 pub resolution_time_mins: i32,
42}
43
44#[derive(Debug, Clone, Deserialize)]
53#[cfg_attr(feature = "openapi", derive(ToSchema))]
54#[serde(rename_all = "camelCase")]
55pub struct UpdateServiceLevelPriorityDto {
56 #[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
57 #[serde(alias = "sla_id")]
58 pub sla_id: Uuid,
59 pub priority: IssuePriority,
60 #[cfg_attr(feature = "openapi", schema(example = 42))]
61 #[serde(alias = "response_time_mins")]
62 pub response_time_mins: i32,
63 #[cfg_attr(feature = "openapi", schema(example = 42))]
64 #[serde(alias = "resolution_time_mins")]
65 pub resolution_time_mins: i32,
66}
67
68#[derive(Debug, Clone, Default, Deserialize)]
77#[cfg_attr(feature = "openapi", derive(ToSchema))]
78#[serde(rename_all = "camelCase")]
79pub struct PatchServiceLevelPriorityDto {
80 #[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
81 #[serde(skip_serializing_if = "Option::is_none", alias = "sla_id")]
82 pub sla_id: Option<Uuid>,
83 #[serde(skip_serializing_if = "Option::is_none")]
84 pub priority: Option<IssuePriority>,
85 #[cfg_attr(feature = "openapi", schema(example = 42))]
86 #[serde(skip_serializing_if = "Option::is_none", alias = "response_time_mins")]
87 pub response_time_mins: Option<i32>,
88 #[cfg_attr(feature = "openapi", schema(example = 42))]
89 #[serde(skip_serializing_if = "Option::is_none", alias = "resolution_time_mins")]
90 pub resolution_time_mins: Option<i32>,
91}
92
93impl PatchServiceLevelPriorityDto {
94 pub fn has_changes(&self) -> bool {
96 self.sla_id.is_some() || self.priority.is_some() || self.response_time_mins.is_some() || self.resolution_time_mins.is_some()
97 }
98}
99
100#[derive(Debug, Clone, Serialize)]
109#[cfg_attr(feature = "openapi", derive(ToSchema))]
110#[serde(rename_all = "camelCase")]
111pub struct ServiceLevelPriorityResponseDto {
112 #[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
113 pub id: Uuid,
114 #[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
115 pub sla_id: Uuid,
116 pub priority: IssuePriority,
117 #[cfg_attr(feature = "openapi", schema(example = 42))]
118 pub response_time_mins: i32,
119 #[cfg_attr(feature = "openapi", schema(example = 42))]
120 pub resolution_time_mins: i32,
121 pub metadata: AuditMetadata,
122}
123
124#[derive(Debug, Clone, Serialize)]
133#[cfg_attr(feature = "openapi", derive(ToSchema))]
134#[serde(rename_all = "camelCase")]
135pub struct ServiceLevelPriorityListResponseDto {
136 pub items: Vec<ServiceLevelPriorityResponseDto>,
138 pub total: u64,
140 pub page: u32,
142 pub per_page: u32,
144 pub total_pages: u32,
146 pub has_next: bool,
148 pub has_prev: bool,
150}
151
152impl ServiceLevelPriorityListResponseDto {
153 pub fn new(items: Vec<ServiceLevelPriorityResponseDto>, total: u64, page: u32, per_page: u32) -> Self {
155 let total_pages = if per_page > 0 {
156 ((total as f64) / (per_page as f64)).ceil() as u32
157 } else {
158 0
159 };
160 Self {
161 items,
162 total,
163 page,
164 per_page,
165 total_pages,
166 has_next: page < total_pages,
167 has_prev: page > 1,
168 }
169 }
170}
171
172#[derive(Debug, Clone, Serialize)]
174#[cfg_attr(feature = "openapi", derive(ToSchema))]
175#[serde(rename_all = "camelCase")]
176pub struct ServiceLevelPrioritySummaryDto {
177 pub id: Uuid,
178 pub sla_id: Uuid,
179 pub priority: IssuePriority,
180 pub response_time_mins: i32,
181 pub created_at: Option<DateTime<Utc>>,
182}
183
184impl From<ServiceLevelPriority> for ServiceLevelPriorityResponseDto {
189 fn from(entity: ServiceLevelPriority) -> Self {
190 Self {
191 id: entity.id,
192 sla_id: entity.sla_id,
193 priority: entity.priority,
194 response_time_mins: entity.response_time_mins,
195 resolution_time_mins: entity.resolution_time_mins,
196 metadata: entity.metadata,
197 }
198 }
199}
200
201impl From<ServiceLevelPriority> for ServiceLevelPrioritySummaryDto {
202 fn from(entity: ServiceLevelPriority) -> Self {
203 let created_at = backbone_core::PersistentEntity::created_at(&entity);
204 Self {
205 id: entity.id,
206 sla_id: entity.sla_id,
207 priority: entity.priority,
208 response_time_mins: entity.response_time_mins,
209 created_at,
210 }
211 }
212}
213
214impl From<CreateServiceLevelPriorityDto> for ServiceLevelPriority {
215 fn from(dto: CreateServiceLevelPriorityDto) -> Self {
216 Self {
217 id: Uuid::new_v4(),
218 sla_id: dto.sla_id,
219 priority: dto.priority,
220 response_time_mins: dto.response_time_mins,
221 resolution_time_mins: dto.resolution_time_mins,
222 metadata: AuditMetadata::default(),
223 }
224 }
225}
226
227impl From<&ServiceLevelPriority> for ServiceLevelPriorityResponseDto {
228 fn from(entity: &ServiceLevelPriority) -> Self {
229 Self {
230 id: entity.id.clone(),
231 sla_id: entity.sla_id.clone(),
232 priority: entity.priority.clone(),
233 response_time_mins: entity.response_time_mins.clone(),
234 resolution_time_mins: entity.resolution_time_mins.clone(),
235 metadata: entity.metadata.clone(),
236 }
237 }
238}
239
240impl backbone_core::FromCreateDto<CreateServiceLevelPriorityDto> for ServiceLevelPriority {
241 fn from_create_dto(dto: CreateServiceLevelPriorityDto) -> backbone_core::ServiceResult<Self> {
242 Ok(ServiceLevelPriority::from(dto))
243 }
244}
245
246impl backbone_core::ApplyUpdateDto<UpdateServiceLevelPriorityDto> for ServiceLevelPriority {
247 fn apply_update(mut self, dto: UpdateServiceLevelPriorityDto) -> backbone_core::ServiceResult<Self> {
248 self.sla_id = dto.sla_id;
249 self.priority = dto.priority;
250 self.response_time_mins = dto.response_time_mins;
251 self.resolution_time_mins = dto.resolution_time_mins;
252 Ok(self)
253 }
254}
255
256