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