pub mod issue_dto;
pub mod service_level_agreement_dto;
pub mod service_level_priority_dto;
pub mod warranty_claim_dto;
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,
};
use serde::Serialize;
#[cfg(feature = "openapi")]
#[cfg(feature = "openapi")]
use utoipa::ToSchema;
#[derive(Debug, Clone, Default, serde::Deserialize)]
#[cfg_attr(feature = "openapi", derive(ToSchema))]
pub struct PaginationParams {
#[serde(default = "default_page")]
pub page: u32,
#[serde(default = "default_per_page")]
pub per_page: u32,
pub sort_by: Option<String>,
pub sort_order: Option<String>,
}
fn default_page() -> u32 { 1 }
fn default_per_page() -> u32 { 20 }
#[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,
}),
}
}
}