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;
#[derive(Debug, Clone)]
pub struct GetContentHashInput {
pub id: Uuid,
}
#[derive(Debug, Clone)]
pub struct GetContentHashOutput {
pub content_hash: ContentHash,
}
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 })
}
}