backbone-bucket 0.3.0

Bucket Bounded Context: File Storage Module for Backbone Framework
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 access_log_dto;
pub mod bucket_dto;
pub mod content_hash_dto;
pub mod conversion_job_dto;
pub mod file_comment_dto;
pub mod file_lock_dto;
pub mod file_share_dto;
pub mod file_version_dto;
pub mod processing_job_dto;
pub mod stored_file_dto;
pub mod thumbnail_dto;
pub mod upload_session_dto;
pub mod user_quota_dto;

// Re-exports
pub use access_log_dto::{
    CreateAccessLogDto,
    UpdateAccessLogDto,
    PatchAccessLogDto,
    AccessLogResponseDto,
    AccessLogListResponseDto,
    AccessLogSummaryDto,
};
pub use bucket_dto::{
    CreateBucketDto,
    UpdateBucketDto,
    PatchBucketDto,
    BucketResponseDto,
    BucketListResponseDto,
    BucketSummaryDto,
};
pub use content_hash_dto::{
    CreateContentHashDto,
    UpdateContentHashDto,
    PatchContentHashDto,
    ContentHashResponseDto,
    ContentHashListResponseDto,
    ContentHashSummaryDto,
};
pub use conversion_job_dto::{
    CreateConversionJobDto,
    UpdateConversionJobDto,
    PatchConversionJobDto,
    ConversionJobResponseDto,
    ConversionJobListResponseDto,
    ConversionJobSummaryDto,
};
pub use file_comment_dto::{
    CreateFileCommentDto,
    UpdateFileCommentDto,
    PatchFileCommentDto,
    FileCommentResponseDto,
    FileCommentListResponseDto,
    FileCommentSummaryDto,
};
pub use file_lock_dto::{
    CreateFileLockDto,
    UpdateFileLockDto,
    PatchFileLockDto,
    FileLockResponseDto,
    FileLockListResponseDto,
    FileLockSummaryDto,
};
pub use file_share_dto::{
    CreateFileShareDto,
    UpdateFileShareDto,
    PatchFileShareDto,
    FileShareResponseDto,
    FileShareListResponseDto,
    FileShareSummaryDto,
};
pub use file_version_dto::{
    CreateFileVersionDto,
    UpdateFileVersionDto,
    PatchFileVersionDto,
    FileVersionResponseDto,
    FileVersionListResponseDto,
    FileVersionSummaryDto,
};
pub use processing_job_dto::{
    CreateProcessingJobDto,
    UpdateProcessingJobDto,
    PatchProcessingJobDto,
    ProcessingJobResponseDto,
    ProcessingJobListResponseDto,
    ProcessingJobSummaryDto,
};
pub use stored_file_dto::{
    CreateStoredFileDto,
    UpdateStoredFileDto,
    PatchStoredFileDto,
    StoredFileResponseDto,
    StoredFileListResponseDto,
    StoredFileSummaryDto,
};
pub use thumbnail_dto::{
    CreateThumbnailDto,
    UpdateThumbnailDto,
    PatchThumbnailDto,
    ThumbnailResponseDto,
    ThumbnailListResponseDto,
    ThumbnailSummaryDto,
};
pub use upload_session_dto::{
    CreateUploadSessionDto,
    UpdateUploadSessionDto,
    PatchUploadSessionDto,
    UploadSessionResponseDto,
    UploadSessionListResponseDto,
    UploadSessionSummaryDto,
};
pub use user_quota_dto::{
    CreateUserQuotaDto,
    UpdateUserQuotaDto,
    PatchUserQuotaDto,
    UserQuotaResponseDto,
    UserQuotaListResponseDto,
    UserQuotaSummaryDto,
};

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