backbone-bucket 0.2.1

Bucket Bounded Context: File Storage Module for Backbone Framework
Documentation
//! Create ConversionJob 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::ConversionJob;
use crate::infrastructure::persistence::ConversionJobRepository;

/// Input for creating a ConversionJob
#[derive(Debug, Clone)]
pub struct CreateConversionJobInput {
    pub source_file_id: Uuid,
    pub target_format: String,
    pub status: ConversionStatus,
    pub conversion_options: Option<serde_json::Value>,
    pub result_file_id: Option<Uuid>,
    pub progress: i32,
    pub error_message: Option<String>,
    pub started_at: Option<DateTime<Utc>>,
    pub completed_at: Option<DateTime<Utc>>,
    pub metadata: Option<serde_json::Value>,
}

/// Output after creating a ConversionJob
#[derive(Debug, Clone)]
pub struct CreateConversionJobOutput {
    pub conversion_job: ConversionJob,
}

/// Use case for creating a new ConversionJob
pub struct CreateConversionJobUseCase {
    repository: Arc<ConversionJobRepository>,
}

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

#[async_trait]
impl UseCase for CreateConversionJobUseCase {
    type Input = CreateConversionJobInput;
    type Output = CreateConversionJobOutput;

    async fn execute(&self, input: Self::Input) -> Result<Self::Output> {
        // Create entity from input
        let entity = ConversionJob {
            id: None,
            source_file_id: input.source_file_id,
            target_format: input.target_format,
            status: input.status,
            conversion_options: input.conversion_options,
            result_file_id: input.result_file_id,
            progress: input.progress,
            error_message: input.error_message,
            started_at: input.started_at,
            completed_at: input.completed_at,
            metadata: input.metadata,
        };

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

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

        Ok(CreateConversionJobOutput { conversion_job: created })
    }
}