backbone-bucket 0.2.0

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

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

/// Output containing the AccessLog
#[derive(Debug, Clone)]
pub struct GetAccessLogOutput {
    pub access_log: AccessLog,
}

/// Use case for getting a AccessLog by ID
pub struct GetAccessLogUseCase {
    repository: Arc<AccessLogRepository>,
}

impl GetAccessLogUseCase {
    pub fn new(repository: Arc<AccessLogRepository>) -> Self {
        Self { repository }
    }
}

#[async_trait]
impl UseCase for GetAccessLogUseCase {
    type Input = GetAccessLogInput;
    type Output = GetAccessLogOutput;

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

        Ok(GetAccessLogOutput { access_log: entity })
    }
}