backbone-bucket 0.2.1

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

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

/// Output containing the UserQuota
#[derive(Debug, Clone)]
pub struct GetUserQuotaOutput {
    pub user_quota: UserQuota,
}

/// Use case for getting a UserQuota by ID
pub struct GetUserQuotaUseCase {
    repository: Arc<UserQuotaRepository>,
}

impl GetUserQuotaUseCase {
    pub fn new(repository: Arc<UserQuotaRepository>) -> Self {
        Self { repository }
    }
}

#[async_trait]
impl UseCase for GetUserQuotaUseCase {
    type Input = GetUserQuotaInput;
    type Output = GetUserQuotaOutput;

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

        Ok(GetUserQuotaOutput { user_quota: entity })
    }
}