Skip to main content

backbone_support/presentation/dto/
mod.rs

1//! DTOs (Data Transfer Objects)
2//!
3//! Generated by metaphor-schema. Do not edit manually.
4//!
5//! This module provides DTOs for the presentation layer,
6//! with OpenAPI schema support.
7
8pub mod issue_dto;
9pub mod service_level_agreement_dto;
10pub mod service_level_priority_dto;
11pub mod warranty_claim_dto;
12
13// Re-exports
14pub use issue_dto::{
15    CreateIssueDto,
16    UpdateIssueDto,
17    PatchIssueDto,
18    IssueResponseDto,
19    IssueListResponseDto,
20    IssueSummaryDto,
21};
22pub use service_level_agreement_dto::{
23    CreateServiceLevelAgreementDto,
24    UpdateServiceLevelAgreementDto,
25    PatchServiceLevelAgreementDto,
26    ServiceLevelAgreementResponseDto,
27    ServiceLevelAgreementListResponseDto,
28    ServiceLevelAgreementSummaryDto,
29};
30pub use service_level_priority_dto::{
31    CreateServiceLevelPriorityDto,
32    UpdateServiceLevelPriorityDto,
33    PatchServiceLevelPriorityDto,
34    ServiceLevelPriorityResponseDto,
35    ServiceLevelPriorityListResponseDto,
36    ServiceLevelPrioritySummaryDto,
37};
38pub use warranty_claim_dto::{
39    CreateWarrantyClaimDto,
40    UpdateWarrantyClaimDto,
41    PatchWarrantyClaimDto,
42    WarrantyClaimResponseDto,
43    WarrantyClaimListResponseDto,
44    WarrantyClaimSummaryDto,
45};
46
47// Common pagination types
48use serde::Serialize;
49
50#[cfg(feature = "openapi")]
51#[cfg(feature = "openapi")]
52use utoipa::ToSchema;
53
54/// Pagination parameters for list requests
55#[derive(Debug, Clone, Default, serde::Deserialize)]
56#[cfg_attr(feature = "openapi", derive(ToSchema))]
57pub struct PaginationParams {
58    /// Page number (1-indexed)
59    #[serde(default = "default_page")]
60    pub page: u32,
61    /// Items per page
62    #[serde(default = "default_per_page")]
63    pub per_page: u32,
64    /// Field to sort by
65    pub sort_by: Option<String>,
66    /// Sort order (asc/desc)
67    pub sort_order: Option<String>,
68}
69
70fn default_page() -> u32 { 1 }
71fn default_per_page() -> u32 { 20 }
72
73/// API response wrapper
74#[derive(Debug, Clone, Serialize)]
75#[cfg_attr(feature = "openapi", derive(ToSchema))]
76#[serde(rename_all = "camelCase")]
77pub struct ApiResponse<T> {
78    pub success: bool,
79    #[serde(skip_serializing_if = "Option::is_none")]
80    pub data: Option<T>,
81    #[serde(skip_serializing_if = "Option::is_none")]
82    pub error: Option<ApiError>,
83}
84
85#[derive(Debug, Clone, Serialize)]
86#[cfg_attr(feature = "openapi", derive(ToSchema))]
87pub struct ApiError {
88    pub code: String,
89    pub message: String,
90    #[serde(skip_serializing_if = "Option::is_none")]
91    pub details: Option<serde_json::Value>,
92}
93
94impl<T> ApiResponse<T> {
95    pub fn ok(data: T) -> Self {
96        Self { success: true, data: Some(data), error: None }
97    }
98
99    pub fn err(code: impl Into<String>, message: impl Into<String>) -> Self {
100        Self {
101            success: false,
102            data: None,
103            error: Some(ApiError {
104                code: code.into(),
105                message: message.into(),
106                details: None,
107            }),
108        }
109    }
110}