backbone-support 0.6.15

Minimal Backbone Framework module skeleton
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 issue_dto;
pub mod service_level_agreement_dto;
pub mod service_level_priority_dto;
pub mod warranty_claim_dto;

// Re-exports
pub use issue_dto::{
    CreateIssueDto,
    UpdateIssueDto,
    PatchIssueDto,
    IssueResponseDto,
    IssueListResponseDto,
    IssueSummaryDto,
};
pub use service_level_agreement_dto::{
    CreateServiceLevelAgreementDto,
    UpdateServiceLevelAgreementDto,
    PatchServiceLevelAgreementDto,
    ServiceLevelAgreementResponseDto,
    ServiceLevelAgreementListResponseDto,
    ServiceLevelAgreementSummaryDto,
};
pub use service_level_priority_dto::{
    CreateServiceLevelPriorityDto,
    UpdateServiceLevelPriorityDto,
    PatchServiceLevelPriorityDto,
    ServiceLevelPriorityResponseDto,
    ServiceLevelPriorityListResponseDto,
    ServiceLevelPrioritySummaryDto,
};
pub use warranty_claim_dto::{
    CreateWarrantyClaimDto,
    UpdateWarrantyClaimDto,
    PatchWarrantyClaimDto,
    WarrantyClaimResponseDto,
    WarrantyClaimListResponseDto,
    WarrantyClaimSummaryDto,
};

// 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,
            }),
        }
    }
}