backbone-bucket 0.3.0

Bucket Bounded Context: File Storage Module for Backbone Framework
Documentation
//! FileComment DTOs (Data Transfer Objects)
//!
//! Generated by metaphor-schema. Do not edit manually.
//!
//! DTOs provide a clean separation between domain entities and API
//! representations, with validation and OpenAPI documentation support.

use serde::{Deserialize, Serialize};
use uuid::Uuid;
use chrono::{DateTime, Utc};

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

#[cfg(feature = "validation")]
use validator::Validate;

use crate::domain::entity::FileComment;
use crate::domain::entity::AuditMetadata;
use crate::domain::entity::CommentStatus;

// =============================================================================
// Create DTO
// =============================================================================

/// Request DTO for creating a new FileComment
///
/// Used in POST requests to create new entities.
/// Excludes auto-generated fields (id, created_at, updated_at, deleted_at).
#[derive(Debug, Clone, Deserialize)]
#[cfg_attr(feature = "openapi", derive(ToSchema))]
#[cfg_attr(feature = "validation", derive(Validate))]
#[serde(rename_all = "camelCase")]
pub struct CreateFileCommentDto {
    #[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
    #[serde(alias = "file_id")]
    pub file_id: Uuid,
    #[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
    #[serde(alias = "user_id")]
    pub user_id: Uuid,
    #[serde(default, skip_serializing_if = "Option::is_none", alias = "parent_id")]
    pub parent_id: Option<Uuid>,
    #[cfg_attr(feature = "validation", validate(length(max = 10000)))]
    #[cfg_attr(feature = "openapi", schema(example = "example"))]
    pub content: String,
    #[serde(default, skip_serializing_if = "Option::is_none", alias = "annotation_region")]
    pub annotation_region: Option<serde_json::Value>,
    pub mentions: Vec<Uuid>,
    #[cfg_attr(feature = "openapi", schema(example = true))]
    pub resolved: bool,
    #[serde(default, skip_serializing_if = "Option::is_none", alias = "resolved_by")]
    pub resolved_by: Option<Uuid>,
    #[serde(default, skip_serializing_if = "Option::is_none", alias = "resolved_at")]
    pub resolved_at: Option<DateTime<Utc>>,
    pub status: CommentStatus,
}

// =============================================================================
// Update DTO
// =============================================================================

/// Request DTO for full update of a FileComment
///
/// Used in PUT requests for full entity replacement.
/// All fields are required (except auto-generated ones).
#[derive(Debug, Clone, Deserialize)]
#[cfg_attr(feature = "openapi", derive(ToSchema))]
#[cfg_attr(feature = "validation", derive(Validate))]
#[serde(rename_all = "camelCase")]
pub struct UpdateFileCommentDto {
    #[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
    #[serde(alias = "file_id")]
    pub file_id: Uuid,
    #[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
    #[serde(alias = "user_id")]
    pub user_id: Uuid,
    #[serde(default, skip_serializing_if = "Option::is_none", alias = "parent_id")]
    pub parent_id: Option<Uuid>,
    #[cfg_attr(feature = "validation", validate(length(max = 10000)))]
    #[cfg_attr(feature = "openapi", schema(example = "example"))]
    pub content: String,
    #[serde(default, skip_serializing_if = "Option::is_none", alias = "annotation_region")]
    pub annotation_region: Option<serde_json::Value>,
    pub mentions: Vec<Uuid>,
    #[cfg_attr(feature = "openapi", schema(example = true))]
    pub resolved: bool,
    #[serde(default, skip_serializing_if = "Option::is_none", alias = "resolved_by")]
    pub resolved_by: Option<Uuid>,
    #[serde(default, skip_serializing_if = "Option::is_none", alias = "resolved_at")]
    pub resolved_at: Option<DateTime<Utc>>,
    pub status: CommentStatus,
}

// =============================================================================
// Patch DTO
// =============================================================================

/// Request DTO for partial update of a FileComment
///
/// Used in PATCH requests for partial updates.
/// All fields are optional - only provided fields will be updated.
#[derive(Debug, Clone, Default, Deserialize)]
#[cfg_attr(feature = "openapi", derive(ToSchema))]
#[cfg_attr(feature = "validation", derive(Validate))]
#[serde(rename_all = "camelCase")]
pub struct PatchFileCommentDto {
    #[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
    #[serde(skip_serializing_if = "Option::is_none", alias = "file_id")]
    pub file_id: Option<Uuid>,
    #[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
    #[serde(skip_serializing_if = "Option::is_none", alias = "user_id")]
    pub user_id: Option<Uuid>,
    #[serde(skip_serializing_if = "Option::is_none", alias = "parent_id")]
    pub parent_id: Option<Uuid>,
    #[cfg_attr(feature = "validation", validate(length(max = 10000)))]
    #[cfg_attr(feature = "openapi", schema(example = "example"))]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub content: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none", alias = "annotation_region")]
    pub annotation_region: Option<serde_json::Value>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub mentions: Option<Vec<Uuid>>,
    #[cfg_attr(feature = "openapi", schema(example = true))]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub resolved: Option<bool>,
    #[serde(skip_serializing_if = "Option::is_none", alias = "resolved_by")]
    pub resolved_by: Option<Uuid>,
    #[serde(skip_serializing_if = "Option::is_none", alias = "resolved_at")]
    pub resolved_at: Option<DateTime<Utc>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub status: Option<CommentStatus>,
}

impl PatchFileCommentDto {
    /// Check if any field is set
    pub fn has_changes(&self) -> bool {
        self.file_id.is_some() || self.user_id.is_some() || self.parent_id.is_some() || self.content.is_some() || self.annotation_region.is_some() || self.mentions.is_some() || self.resolved.is_some() || self.resolved_by.is_some() || self.resolved_at.is_some() || self.status.is_some()
    }
}

// =============================================================================
// Response DTO
// =============================================================================

/// Response DTO for FileComment entity
///
/// Used in API responses for single entity.
/// Includes all fields including metadata.
#[derive(Debug, Clone, Serialize)]
#[cfg_attr(feature = "openapi", derive(ToSchema))]
#[serde(rename_all = "camelCase")]
pub struct FileCommentResponseDto {
    #[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
    pub id: Uuid,
    #[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
    pub file_id: Uuid,
    #[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
    pub user_id: Uuid,
    pub parent_id: Option<Uuid>,
    #[cfg_attr(feature = "openapi", schema(example = "example"))]
    pub content: String,
    pub annotation_region: Option<serde_json::Value>,
    pub mentions: Vec<Uuid>,
    #[cfg_attr(feature = "openapi", schema(example = true))]
    pub resolved: bool,
    pub resolved_by: Option<Uuid>,
    pub resolved_at: Option<DateTime<Utc>>,
    pub status: CommentStatus,
    pub metadata: AuditMetadata,
}

// =============================================================================
// List Response DTO
// =============================================================================

/// Paginated list response for FileComment entities
///
/// Used in API responses for list endpoints.
/// Includes pagination metadata.
#[derive(Debug, Clone, Serialize)]
#[cfg_attr(feature = "openapi", derive(ToSchema))]
#[serde(rename_all = "camelCase")]
pub struct FileCommentListResponseDto {
    /// List of items
    pub items: Vec<FileCommentResponseDto>,
    /// Total number of items (across all pages)
    pub total: u64,
    /// Current page number (1-indexed)
    pub page: u32,
    /// Number of items per page
    pub per_page: u32,
    /// Total number of pages
    pub total_pages: u32,
    /// Whether there is a next page
    pub has_next: bool,
    /// Whether there is a previous page
    pub has_prev: bool,
}

impl FileCommentListResponseDto {
    /// Create a new list response from items and pagination info
    pub fn new(items: Vec<FileCommentResponseDto>, total: u64, page: u32, per_page: u32) -> Self {
        let total_pages = if per_page > 0 {
            ((total as f64) / (per_page as f64)).ceil() as u32
        } else {
            0
        };
        Self {
            items,
            total,
            page,
            per_page,
            total_pages,
            has_next: page < total_pages,
            has_prev: page > 1,
        }
    }
}

/// Summary DTO for list views (compact version)
#[derive(Debug, Clone, Serialize)]
#[cfg_attr(feature = "openapi", derive(ToSchema))]
#[serde(rename_all = "camelCase")]
pub struct FileCommentSummaryDto {
    pub id: Uuid,
    pub file_id: Uuid,
    pub user_id: Uuid,
    pub parent_id: Option<Uuid>,
    pub created_at: Option<DateTime<Utc>>,
}

// =============================================================================
// Conversions
// =============================================================================

impl From<FileComment> for FileCommentResponseDto {
    fn from(entity: FileComment) -> Self {
        Self {
            id: entity.id,
            file_id: entity.file_id,
            user_id: entity.user_id,
            parent_id: entity.parent_id,
            content: entity.content,
            annotation_region: entity.annotation_region,
            mentions: entity.mentions,
            resolved: entity.resolved,
            resolved_by: entity.resolved_by,
            resolved_at: entity.resolved_at,
            status: entity.status,
            metadata: entity.metadata,
        }
    }
}

impl From<FileComment> for FileCommentSummaryDto {
    fn from(entity: FileComment) -> Self {
        let created_at = backbone_core::PersistentEntity::created_at(&entity);
        Self {
            id: entity.id,
            file_id: entity.file_id,
            user_id: entity.user_id,
            parent_id: entity.parent_id,
            created_at,
        }
    }
}

impl From<CreateFileCommentDto> for FileComment {
    fn from(dto: CreateFileCommentDto) -> Self {
        Self {
            id: Uuid::new_v4(),
            file_id: dto.file_id,
            user_id: dto.user_id,
            parent_id: dto.parent_id,
            content: dto.content,
            annotation_region: dto.annotation_region,
            mentions: dto.mentions,
            resolved: dto.resolved,
            resolved_by: dto.resolved_by,
            resolved_at: dto.resolved_at,
            status: dto.status,
            metadata: AuditMetadata::default(),
        }
    }
}

impl From<&FileComment> for FileCommentResponseDto {
    fn from(entity: &FileComment) -> Self {
        Self {
            id: entity.id.clone(),
            file_id: entity.file_id.clone(),
            user_id: entity.user_id.clone(),
            parent_id: entity.parent_id.clone(),
            content: entity.content.clone(),
            annotation_region: entity.annotation_region.clone(),
            mentions: entity.mentions.clone(),
            resolved: entity.resolved.clone(),
            resolved_by: entity.resolved_by.clone(),
            resolved_at: entity.resolved_at.clone(),
            status: entity.status.clone(),
            metadata: entity.metadata.clone(),
        }
    }
}

impl backbone_core::FromCreateDto<CreateFileCommentDto> for FileComment {
    fn from_create_dto(dto: CreateFileCommentDto) -> backbone_core::ServiceResult<Self> {
        Ok(FileComment::from(dto))
    }
}

impl backbone_core::ApplyUpdateDto<UpdateFileCommentDto> for FileComment {
    fn apply_update(mut self, dto: UpdateFileCommentDto) -> backbone_core::ServiceResult<Self> {
        self.file_id = dto.file_id;
        self.user_id = dto.user_id;
        self.parent_id = dto.parent_id;
        self.content = dto.content;
        self.annotation_region = dto.annotation_region;
        self.mentions = dto.mentions;
        self.resolved = dto.resolved;
        self.resolved_by = dto.resolved_by;
        self.resolved_at = dto.resolved_at;
        self.status = dto.status;
        Ok(self)
    }
}

// =============================================================================
// Custom DTOs
// =============================================================================

// <<< CUSTOM DTOs
// Add custom DTOs specific to FileComment here.
// This section will be preserved during regeneration.
// >>> END CUSTOM DTOs