backbone-bucket 0.2.0

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

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

/// Output containing the StoredFile
#[derive(Debug, Clone)]
pub struct GetStoredFileOutput {
    pub stored_file: StoredFile,
}

/// Use case for getting a StoredFile by ID
pub struct GetStoredFileUseCase {
    repository: Arc<StoredFileRepository>,
}

impl GetStoredFileUseCase {
    pub fn new(repository: Arc<StoredFileRepository>) -> Self {
        Self { repository }
    }
}

#[async_trait]
impl UseCase for GetStoredFileUseCase {
    type Input = GetStoredFileInput;
    type Output = GetStoredFileOutput;

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

        Ok(GetStoredFileOutput { stored_file: entity })
    }
}