backbone-bucket 0.3.0

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

/// ProcessingJob 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 ProcessingJobProjection {
    pub id: Uuid,
    pub file_id: Uuid,
    pub job_type: ProcessingJobType,
    pub status: JobStatus,
    pub priority: i32,
    pub input_data: Option<serde_json::Value>,
    pub result_data: Option<serde_json::Value>,
    pub error_message: Option<String>,
    pub started_at: Option<DateTime<Utc>>,
    pub completed_at: Option<DateTime<Utc>>,
    pub retry_count: i32,
    pub max_retries: i32,
    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 ProcessingJobProjection {
    /// Create a new projection from entity data
    pub fn new(
        id: Uuid,
        file_id: Uuid,
        job_type: ProcessingJobType,
        status: JobStatus,
        priority: i32,
        input_data: Option<serde_json::Value>,
        result_data: Option<serde_json::Value>,
        error_message: Option<String>,
        started_at: Option<DateTime<Utc>>,
        completed_at: Option<DateTime<Utc>>,
        retry_count: i32,
        max_retries: i32,
        metadata: serde_json::Value
    ) -> Self {
        Self {
            id,
            file_id,
            job_type,
            status,
            priority,
            input_data,
            result_data,
            error_message,
            started_at,
            completed_at,
            retry_count,
            max_retries,
            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 ProcessingJob for list displays
#[derive(Debug, Clone, Serialize, Deserialize, FromRow)]
pub struct ProcessingJobSummary {
    pub id: Uuid,
    pub status: JobStatus,
}

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