backbone-bucket 0.2.1

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

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

/// Output containing the ContentHash
#[derive(Debug, Clone)]
pub struct GetContentHashOutput {
    pub content_hash: ContentHash,
}

/// Use case for getting a ContentHash by ID
pub struct GetContentHashUseCase {
    repository: Arc<ContentHashRepository>,
}

impl GetContentHashUseCase {
    pub fn new(repository: Arc<ContentHashRepository>) -> Self {
        Self { repository }
    }
}

#[async_trait]
impl UseCase for GetContentHashUseCase {
    type Input = GetContentHashInput;
    type Output = GetContentHashOutput;

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

        Ok(GetContentHashOutput { content_hash: entity })
    }
}