Skip to main content

backbone_payroll/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 validation and OpenAPI schema support.
7
8pub mod compensation_change_dto;
9pub mod payroll_entry_dto;
10pub mod salary_slip_dto;
11pub mod salary_slip_line_dto;
12pub mod salary_structure_dto;
13pub mod salary_component_dto;
14
15// Re-exports
16pub use compensation_change_dto::{
17    CreateCompensationChangeDto,
18    UpdateCompensationChangeDto,
19    PatchCompensationChangeDto,
20    CompensationChangeResponseDto,
21    CompensationChangeListResponseDto,
22    CompensationChangeSummaryDto,
23};
24pub use payroll_entry_dto::{
25    CreatePayrollEntryDto,
26    UpdatePayrollEntryDto,
27    PatchPayrollEntryDto,
28    PayrollEntryResponseDto,
29    PayrollEntryListResponseDto,
30    PayrollEntrySummaryDto,
31};
32pub use salary_slip_dto::{
33    CreateSalarySlipDto,
34    UpdateSalarySlipDto,
35    PatchSalarySlipDto,
36    SalarySlipResponseDto,
37    SalarySlipListResponseDto,
38    SalarySlipSummaryDto,
39};
40pub use salary_slip_line_dto::{
41    CreateSalarySlipLineDto,
42    UpdateSalarySlipLineDto,
43    PatchSalarySlipLineDto,
44    SalarySlipLineResponseDto,
45    SalarySlipLineListResponseDto,
46    SalarySlipLineSummaryDto,
47};
48pub use salary_structure_dto::{
49    CreateSalaryStructureDto,
50    UpdateSalaryStructureDto,
51    PatchSalaryStructureDto,
52    SalaryStructureResponseDto,
53    SalaryStructureListResponseDto,
54    SalaryStructureSummaryDto,
55};
56pub use salary_component_dto::{
57    CreateSalaryComponentDto,
58    UpdateSalaryComponentDto,
59    PatchSalaryComponentDto,
60    SalaryComponentResponseDto,
61    SalaryComponentListResponseDto,
62    SalaryComponentSummaryDto,
63};
64
65// Common pagination types
66use serde::Serialize;
67
68#[cfg(feature = "openapi")]
69#[cfg(feature = "openapi")]
70use utoipa::ToSchema;
71
72/// Pagination parameters for list requests
73#[derive(Debug, Clone, Default, serde::Deserialize)]
74#[cfg_attr(feature = "openapi", derive(ToSchema))]
75pub struct PaginationParams {
76    /// Page number (1-indexed)
77    #[serde(default = "default_page")]
78    pub page: u32,
79    /// Items per page
80    #[serde(default = "default_per_page")]
81    pub per_page: u32,
82    /// Field to sort by
83    pub sort_by: Option<String>,
84    /// Sort order (asc/desc)
85    pub sort_order: Option<String>,
86}
87
88fn default_page() -> u32 { 1 }
89fn default_per_page() -> u32 { 20 }
90
91/// API response wrapper
92#[derive(Debug, Clone, Serialize)]
93#[cfg_attr(feature = "openapi", derive(ToSchema))]
94#[serde(rename_all = "camelCase")]
95pub struct ApiResponse<T> {
96    pub success: bool,
97    #[serde(skip_serializing_if = "Option::is_none")]
98    pub data: Option<T>,
99    #[serde(skip_serializing_if = "Option::is_none")]
100    pub error: Option<ApiError>,
101}
102
103#[derive(Debug, Clone, Serialize)]
104#[cfg_attr(feature = "openapi", derive(ToSchema))]
105pub struct ApiError {
106    pub code: String,
107    pub message: String,
108    #[serde(skip_serializing_if = "Option::is_none")]
109    pub details: Option<serde_json::Value>,
110}
111
112impl<T> ApiResponse<T> {
113    pub fn ok(data: T) -> Self {
114        Self { success: true, data: Some(data), error: None }
115    }
116
117    pub fn err(code: impl Into<String>, message: impl Into<String>) -> Self {
118        Self {
119            success: false,
120            data: None,
121            error: Some(ApiError {
122                code: code.into(),
123                message: message.into(),
124                details: None,
125            }),
126        }
127    }
128}