backbone-bucket 0.4.3

Bucket Bounded Context: File Storage Module for Backbone Framework
Documentation
//! Thumbnail 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)
// ============================================================================

/// Thumbnail 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 ThumbnailProjection {
    pub id: Uuid,
    pub file_id: Uuid,
    pub size: ThumbnailSize,
    pub width: i32,
    pub height: i32,
    pub storage_key: String,
    pub storage_backend: String,
    pub mime_type: String,
    pub format: String,
    pub quality: i32,
    pub size_bytes: i64,
    pub generated_at: DateTime<Utc>,
    pub generation_time_ms: Option<i32>,
    pub source_version: i32,
    pub cdn_url: Option<String>,
    pub cache_expires_at: Option<DateTime<Utc>>,
    pub is_stale: bool,
    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 ThumbnailProjection {
    /// Create a new projection from entity data
    pub fn new(
        id: Uuid,
        file_id: Uuid,
        size: ThumbnailSize,
        width: i32,
        height: i32,
        storage_key: String,
        storage_backend: String,
        mime_type: String,
        format: String,
        quality: i32,
        size_bytes: i64,
        generated_at: DateTime<Utc>,
        generation_time_ms: Option<i32>,
        source_version: i32,
        cdn_url: Option<String>,
        cache_expires_at: Option<DateTime<Utc>>,
        is_stale: bool,
        metadata: serde_json::Value
    ) -> Self {
        Self {
            id,
            file_id,
            size,
            width,
            height,
            storage_key,
            storage_backend,
            mime_type,
            format,
            quality,
            size_bytes,
            generated_at,
            generation_time_ms,
            source_version,
            cdn_url,
            cache_expires_at,
            is_stale,
            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 Thumbnail for list displays
#[derive(Debug, Clone, Serialize, Deserialize, FromRow)]
pub struct ThumbnailSummary {
    pub id: Uuid,
}

// ============================================================================
// 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 ThumbnailDashboard {
//     pub id: Uuid,
//     pub key_metric: i64,
// }
// <<< CUSTOM PROJECTIONS END >>>