backbone-bucket 0.2.0

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

use std::sync::Arc;

use anyhow::{Result, anyhow};
use async_trait::async_trait;
use uuid::Uuid;

use super::UseCase;
use crate::domain::entity::ConversionJob;
use crate::infrastructure::persistence::ConversionJobRepository;

/// Input for getting a ConversionJob by ID
#[derive(Debug, Clone)]
pub struct GetConversionJobInput {
    pub id: Uuid,
}

/// Output containing the ConversionJob
#[derive(Debug, Clone)]
pub struct GetConversionJobOutput {
    pub conversion_job: ConversionJob,
}

/// Use case for getting a ConversionJob by ID
pub struct GetConversionJobUseCase {
    repository: Arc<ConversionJobRepository>,
}

impl GetConversionJobUseCase {
    pub fn new(repository: Arc<ConversionJobRepository>) -> Self {
        Self { repository }
    }
}

#[async_trait]
impl UseCase for GetConversionJobUseCase {
    type Input = GetConversionJobInput;
    type Output = GetConversionJobOutput;

    async fn execute(&self, input: Self::Input) -> Result<Self::Output> {
        let entity = self.repository.find_by_id(input.id).await?
            .ok_or_else(|| anyhow!("ConversionJob not found"))?;

        Ok(GetConversionJobOutput { conversion_job: entity })
    }
}