backbone-bucket 0.2.1

Bucket Bounded Context: File Storage Module for Backbone Framework
Documentation
//! StoredFile Projection (Read Model)
//!
//! Generated by backbone-schema. Do not edit manually.
//!
//! This is a CQRS projection - an optimized read model for queries.
//! It is updated asynchronously from domain events.

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

// ============================================================================
// PROJECTION (READ MODEL)
// ============================================================================

/// StoredFile read model optimized for queries
///
/// This projection is denormalized for fast reads.
/// It is updated when domain events are published.
#[derive(Debug, Clone, Serialize, Deserialize, FromRow)]
pub struct StoredFileProjection {
    pub id: Uuid,
    pub bucket_id: Uuid,
    pub owner_id: Uuid,
    pub path: String,
    pub original_name: String,
    pub size_bytes: i64,
    pub mime_type: String,
    pub checksum: Option<String>,
    pub is_compressed: bool,
    pub original_size: Option<i64>,
    pub compression_algorithm: Option<String>,
    pub is_scanned: bool,
    pub scan_result: Option<serde_json::Value>,
    pub threat_level: Option<ThreatLevel>,
    pub has_thumbnail: bool,
    pub thumbnail_path: Option<String>,
    pub has_video_thumbnail: bool,
    pub has_document_preview: bool,
    pub processing_status: Option<ProcessingStatus>,
    pub content_hash_id: Option<Uuid>,
    pub cdn_url: Option<String>,
    pub cdn_url_expires_at: Option<DateTime<Utc>>,
    pub owner_module: Option<String>,
    pub owner_entity: Option<String>,
    pub owner_entity_id: Option<Uuid>,
    pub field_name: Option<String>,
    pub sort_order: i32,
    pub status: FileStatus,
    pub storage_key: String,
    pub version: i32,
    pub previous_version_id: Option<Uuid>,
    pub download_count: i32,
    pub last_accessed_at: Option<DateTime<Utc>>,
    pub metadata: serde_json::Value,

    // Projection metadata
    /// Version of the projection (for optimistic locking)
    pub projection_version: i64,
    /// Last event sequence number applied
    pub last_event_sequence: i64,
    /// When this projection was last updated
    pub projection_updated_at: DateTime<Utc>,
}

impl StoredFileProjection {
    /// Create a new projection from entity data
    pub fn new(
        id: Uuid,
        bucket_id: Uuid,
        owner_id: Uuid,
        path: String,
        original_name: String,
        size_bytes: i64,
        mime_type: String,
        checksum: Option<String>,
        is_compressed: bool,
        original_size: Option<i64>,
        compression_algorithm: Option<String>,
        is_scanned: bool,
        scan_result: Option<serde_json::Value>,
        threat_level: Option<ThreatLevel>,
        has_thumbnail: bool,
        thumbnail_path: Option<String>,
        has_video_thumbnail: bool,
        has_document_preview: bool,
        processing_status: Option<ProcessingStatus>,
        content_hash_id: Option<Uuid>,
        cdn_url: Option<String>,
        cdn_url_expires_at: Option<DateTime<Utc>>,
        owner_module: Option<String>,
        owner_entity: Option<String>,
        owner_entity_id: Option<Uuid>,
        field_name: Option<String>,
        sort_order: i32,
        status: FileStatus,
        storage_key: String,
        version: i32,
        previous_version_id: Option<Uuid>,
        download_count: i32,
        last_accessed_at: Option<DateTime<Utc>>,
        metadata: serde_json::Value
    ) -> Self {
        Self {
            id,
            bucket_id,
            owner_id,
            path,
            original_name,
            size_bytes,
            mime_type,
            checksum,
            is_compressed,
            original_size,
            compression_algorithm,
            is_scanned,
            scan_result,
            threat_level,
            has_thumbnail,
            thumbnail_path,
            has_video_thumbnail,
            has_document_preview,
            processing_status,
            content_hash_id,
            cdn_url,
            cdn_url_expires_at,
            owner_module,
            owner_entity,
            owner_entity_id,
            field_name,
            sort_order,
            status,
            storage_key,
            version,
            previous_version_id,
            download_count,
            last_accessed_at,
            metadata,
            projection_version: 1,
            last_event_sequence: 0,
            projection_updated_at: Utc::now(),
        }
    }

    /// Get the projection ID
    pub fn id(&self) -> &Uuid {
        &self.id
    }

    /// Update projection version after applying event
    pub fn apply_event(&mut self, event_sequence: i64) {
        self.projection_version += 1;
        self.last_event_sequence = event_sequence;
        self.projection_updated_at = Utc::now();
    }
}

// ============================================================================
// SUMMARY PROJECTION (LIST VIEW)
// ============================================================================

/// Summary view of StoredFile for list displays
#[derive(Debug, Clone, Serialize, Deserialize, FromRow)]
pub struct StoredFileSummary {
    pub id: Uuid,
    pub original_name: String,
    pub field_name: Option<String>,
    pub status: FileStatus,
}

// ============================================================================
// CUSTOM PROJECTIONS
// ============================================================================
// <<< CUSTOM PROJECTIONS START >>>

// <<< CUSTOM PROJECTIONS START >>>
// Add custom read models here for specific query use cases
// Example:
//
// #[derive(Debug, Clone, Serialize, Deserialize)]
// pub struct StoredFileDashboard {
//     pub id: Uuid,
//     pub key_metric: i64,
// }
// <<< CUSTOM PROJECTIONS END >>>