backbone-bucket 0.3.0

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

/// Bucket 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 BucketProjection {
    pub id: Uuid,
    pub name: String,
    pub slug: String,
    pub description: Option<String>,
    pub owner_id: Uuid,
    pub bucket_type: BucketType,
    pub status: BucketStatus,
    pub storage_backend: StorageBackend,
    pub root_path: String,
    pub file_count: i32,
    pub total_size_bytes: i64,
    pub max_file_size: Option<i64>,
    pub allowed_mime_types: Vec<String>,
    pub auto_delete_after_days: Option<i32>,
    pub enable_cdn: bool,
    pub enable_versioning: bool,
    pub enable_deduplication: 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 BucketProjection {
    /// Create a new projection from entity data
    pub fn new(
        id: Uuid,
        name: String,
        slug: String,
        description: Option<String>,
        owner_id: Uuid,
        bucket_type: BucketType,
        status: BucketStatus,
        storage_backend: StorageBackend,
        root_path: String,
        file_count: i32,
        total_size_bytes: i64,
        max_file_size: Option<i64>,
        allowed_mime_types: Vec<String>,
        auto_delete_after_days: Option<i32>,
        enable_cdn: bool,
        enable_versioning: bool,
        enable_deduplication: bool,
        metadata: serde_json::Value
    ) -> Self {
        Self {
            id,
            name,
            slug,
            description,
            owner_id,
            bucket_type,
            status,
            storage_backend,
            root_path,
            file_count,
            total_size_bytes,
            max_file_size,
            allowed_mime_types,
            auto_delete_after_days,
            enable_cdn,
            enable_versioning,
            enable_deduplication,
            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 Bucket for list displays
#[derive(Debug, Clone, Serialize, Deserialize, FromRow)]
pub struct BucketSummary {
    pub id: Uuid,
    pub name: String,
    pub status: BucketStatus,
}

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