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