use std::sync::Arc;
use anyhow::{Result, anyhow};
use async_trait::async_trait;
use uuid::Uuid;
use super::UseCase;
use crate::domain::entity::ProcessingJob;
use crate::infrastructure::persistence::ProcessingJobRepository;
#[derive(Debug, Clone)]
pub struct GetProcessingJobInput {
pub id: Uuid,
}
#[derive(Debug, Clone)]
pub struct GetProcessingJobOutput {
pub processing_job: ProcessingJob,
}
pub struct GetProcessingJobUseCase {
repository: Arc<ProcessingJobRepository>,
}
impl GetProcessingJobUseCase {
pub fn new(repository: Arc<ProcessingJobRepository>) -> Self {
Self { repository }
}
}
#[async_trait]
impl UseCase for GetProcessingJobUseCase {
type Input = GetProcessingJobInput;
type Output = GetProcessingJobOutput;
async fn execute(&self, input: Self::Input) -> Result<Self::Output> {
let entity = self.repository.find_by_id(input.id).await?
.ok_or_else(|| anyhow!("ProcessingJob not found"))?;
Ok(GetProcessingJobOutput { processing_job: entity })
}
}