backbone-bucket 0.2.1

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

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

/// Output containing the FileComment
#[derive(Debug, Clone)]
pub struct GetFileCommentOutput {
    pub file_comment: FileComment,
}

/// Use case for getting a FileComment by ID
pub struct GetFileCommentUseCase {
    repository: Arc<FileCommentRepository>,
}

impl GetFileCommentUseCase {
    pub fn new(repository: Arc<FileCommentRepository>) -> Self {
        Self { repository }
    }
}

#[async_trait]
impl UseCase for GetFileCommentUseCase {
    type Input = GetFileCommentInput;
    type Output = GetFileCommentOutput;

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

        Ok(GetFileCommentOutput { file_comment: entity })
    }
}