backbone-bucket 0.2.1

Bucket Bounded Context: File Storage Module for Backbone Framework
Documentation
//! Repository trait for ProcessingJob aggregate
//!
//! Generated by metaphor-schema. Do not edit manually.
//!
//! This trait defines the repository contract for the ProcessingJob aggregate.
//! Implementation is in the infrastructure layer.

use async_trait::async_trait;
use anyhow::Result;
use uuid::Uuid;

use crate::domain::entity::{ProcessingJob, JobStatus, ProcessingJobType};

/// Pagination parameters for list queries
#[derive(Debug, Clone, Default)]
pub struct ProcessingJobPaginationParams {
    pub page: u32,
    pub per_page: u32,
}

impl ProcessingJobPaginationParams {
    pub fn new(page: u32, per_page: u32) -> Self {
        Self { page, per_page }
    }

    pub fn offset(&self) -> u64 {
        ((self.page.saturating_sub(1)) * self.per_page) as u64
    }

    pub fn limit(&self) -> u64 {
        self.per_page as u64
    }
}

/// Paginated result for list queries
#[derive(Debug, Clone)]
pub struct ProcessingJobPaginatedResult {
    pub data: Vec<ProcessingJob>,
    pub total: u64,
    pub page: u32,
    pub per_page: u32,
}

/// Filter parameters for list queries
#[derive(Debug, Clone, Default)]
pub struct ProcessingJobFilter {
    pub file_id: Option<Uuid>,
    pub job_type: Option<ProcessingJobType>,
    pub status: Option<JobStatus>,
    pub error_message: Option<String>,
}

impl ProcessingJobFilter {
    /// Check if any filter is set
    pub fn has_filters(&self) -> bool {
        self.file_id.is_some() || self.job_type.is_some() || self.status.is_some() || self.error_message.is_some()
    }
}

/// Repository trait for ProcessingJob aggregate
///
/// This trait defines the persistence contract for ProcessingJob entities.
/// Implementations should be in the infrastructure layer.
#[async_trait]
pub trait ProcessingJobRepository: Send + Sync {

    // =========================================================================
    // Core CRUD Operations
    // =========================================================================

    /// Save a new processing_job entity
    async fn save(&self, entity: &ProcessingJob) -> Result<ProcessingJob>;

    /// Find processing_job by ID
    async fn find_by_id(&self, id: &str) -> Result<Option<ProcessingJob>>;

    /// Find all processing_job entities
    async fn find_all(&self) -> Result<Vec<ProcessingJob>>;

    /// Update processing_job by ID
    async fn update(&self, id: &str, entity: &ProcessingJob) -> Result<Option<ProcessingJob>>;

    /// Delete processing_job by ID
    async fn delete(&self, id: &str) -> Result<bool>;

    // =========================================================================
    // Pagination
    // =========================================================================

    /// List processing_job with pagination
    async fn list(&self, params: ProcessingJobPaginationParams) -> Result<ProcessingJobPaginatedResult>;

    /// List processing_job with pagination and filters
    async fn list_with_filters(&self, params: ProcessingJobPaginationParams, filters: ProcessingJobFilter) -> Result<ProcessingJobPaginatedResult>;

    /// Count all processing_job entities
    async fn count(&self) -> Result<u64>;

    /// Count processing_job entities matching filters
    async fn count_with_filters(&self, filters: ProcessingJobFilter) -> Result<u64>;

    /// Check if processing_job exists by ID
    async fn exists(&self, id: &str) -> Result<bool>;

    // =========================================================================
    // Soft Delete Operations
    // =========================================================================

    /// Soft delete processing_job by ID
    async fn soft_delete(&self, id: &str) -> Result<bool>;

    /// Restore soft-deleted processing_job by ID
    async fn restore(&self, id: &str) -> Result<Option<ProcessingJob>>;

    /// List soft-deleted processing_job entities
    async fn list_deleted(&self, params: ProcessingJobPaginationParams) -> Result<ProcessingJobPaginatedResult>;

    /// Empty trash (permanently delete all soft-deleted entities)
    async fn empty_trash(&self) -> Result<u64>;

    // =========================================================================
    // Bulk Operations
    // =========================================================================

    /// Bulk save processing_job entities
    async fn bulk_save(&self, entities: &[ProcessingJob]) -> Result<Vec<ProcessingJob>>;

    /// Bulk delete by IDs
    async fn bulk_delete(&self, ids: &[&str]) -> Result<u64>;
}