backbone-payroll 0.3.49

Payroll: salary structures, payroll runs and computed salary slips over effective-dated statutory tables, plus compensation changes
Documentation
//! DTOs (Data Transfer Objects)
//!
//! Generated by metaphor-schema. Do not edit manually.
//!
//! This module provides DTOs for the presentation layer,
//! with validation and OpenAPI schema support.

pub mod compensation_change_dto;
pub mod payroll_entry_dto;
pub mod salary_slip_dto;
pub mod salary_slip_line_dto;
pub mod salary_structure_dto;
pub mod salary_component_dto;

// Re-exports
pub use compensation_change_dto::{
    CreateCompensationChangeDto,
    UpdateCompensationChangeDto,
    PatchCompensationChangeDto,
    CompensationChangeResponseDto,
    CompensationChangeListResponseDto,
    CompensationChangeSummaryDto,
};
pub use payroll_entry_dto::{
    CreatePayrollEntryDto,
    UpdatePayrollEntryDto,
    PatchPayrollEntryDto,
    PayrollEntryResponseDto,
    PayrollEntryListResponseDto,
    PayrollEntrySummaryDto,
};
pub use salary_slip_dto::{
    CreateSalarySlipDto,
    UpdateSalarySlipDto,
    PatchSalarySlipDto,
    SalarySlipResponseDto,
    SalarySlipListResponseDto,
    SalarySlipSummaryDto,
};
pub use salary_slip_line_dto::{
    CreateSalarySlipLineDto,
    UpdateSalarySlipLineDto,
    PatchSalarySlipLineDto,
    SalarySlipLineResponseDto,
    SalarySlipLineListResponseDto,
    SalarySlipLineSummaryDto,
};
pub use salary_structure_dto::{
    CreateSalaryStructureDto,
    UpdateSalaryStructureDto,
    PatchSalaryStructureDto,
    SalaryStructureResponseDto,
    SalaryStructureListResponseDto,
    SalaryStructureSummaryDto,
};
pub use salary_component_dto::{
    CreateSalaryComponentDto,
    UpdateSalaryComponentDto,
    PatchSalaryComponentDto,
    SalaryComponentResponseDto,
    SalaryComponentListResponseDto,
    SalaryComponentSummaryDto,
};

// Common pagination types
use serde::Serialize;

#[cfg(feature = "openapi")]
#[cfg(feature = "openapi")]
use utoipa::ToSchema;

/// Pagination parameters for list requests
#[derive(Debug, Clone, Default, serde::Deserialize)]
#[cfg_attr(feature = "openapi", derive(ToSchema))]
pub struct PaginationParams {
    /// Page number (1-indexed)
    #[serde(default = "default_page")]
    pub page: u32,
    /// Items per page
    #[serde(default = "default_per_page")]
    pub per_page: u32,
    /// Field to sort by
    pub sort_by: Option<String>,
    /// Sort order (asc/desc)
    pub sort_order: Option<String>,
}

fn default_page() -> u32 { 1 }
fn default_per_page() -> u32 { 20 }

/// API response wrapper
#[derive(Debug, Clone, Serialize)]
#[cfg_attr(feature = "openapi", derive(ToSchema))]
#[serde(rename_all = "camelCase")]
pub struct ApiResponse<T> {
    pub success: bool,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub data: Option<T>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub error: Option<ApiError>,
}

#[derive(Debug, Clone, Serialize)]
#[cfg_attr(feature = "openapi", derive(ToSchema))]
pub struct ApiError {
    pub code: String,
    pub message: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub details: Option<serde_json::Value>,
}

impl<T> ApiResponse<T> {
    pub fn ok(data: T) -> Self {
        Self { success: true, data: Some(data), error: None }
    }

    pub fn err(code: impl Into<String>, message: impl Into<String>) -> Self {
        Self {
            success: false,
            data: None,
            error: Some(ApiError {
                code: code.into(),
                message: message.into(),
                details: None,
            }),
        }
    }
}