backbone-bucket 0.2.1

Bucket Bounded Context: File Storage Module for Backbone Framework
Documentation
//! Create ProcessingJob use case
//!
//! Generated by backbone-schema. Do not edit manually.

use std::sync::Arc;

use anyhow::Result;
use async_trait::async_trait;

use super::UseCase;
use crate::domain::entity::ProcessingJob;
use crate::infrastructure::persistence::ProcessingJobRepository;

/// Input for creating a ProcessingJob
#[derive(Debug, Clone)]
pub struct CreateProcessingJobInput {
    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: Option<serde_json::Value>,
}

/// Output after creating a ProcessingJob
#[derive(Debug, Clone)]
pub struct CreateProcessingJobOutput {
    pub processing_job: ProcessingJob,
}

/// Use case for creating a new ProcessingJob
pub struct CreateProcessingJobUseCase {
    repository: Arc<ProcessingJobRepository>,
}

impl CreateProcessingJobUseCase {
    /// Create a new use case instance
    pub fn new(repository: Arc<ProcessingJobRepository>) -> Self {
        Self { repository }
    }
}

#[async_trait]
impl UseCase for CreateProcessingJobUseCase {
    type Input = CreateProcessingJobInput;
    type Output = CreateProcessingJobOutput;

    async fn execute(&self, input: Self::Input) -> Result<Self::Output> {
        // Create entity from input
        let entity = ProcessingJob {
            id: None,
            file_id: input.file_id,
            job_type: input.job_type,
            status: input.status,
            priority: input.priority,
            input_data: input.input_data,
            result_data: input.result_data,
            error_message: input.error_message,
            started_at: input.started_at,
            completed_at: input.completed_at,
            retry_count: input.retry_count,
            max_retries: input.max_retries,
            metadata: input.metadata,
        };

        // <<< CUSTOM VALIDATION START >>>
        // Add custom validation logic here
        // <<< CUSTOM VALIDATION END >>>

        // Persist entity
        let created = self.repository.create(entity).await?;

        Ok(CreateProcessingJobOutput { processing_job: created })
    }
}