backbone-bucket 0.2.1

Bucket Bounded Context: File Storage Module for Backbone Framework
Documentation
//! Delete FileAccessLog 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::infrastructure::persistence::FileAccessLogRepository;

/// Input for deleting a FileAccessLog
#[derive(Debug, Clone)]
pub struct DeleteFileAccessLogInput {
    pub id: Uuid,
}

/// Output after deleting a FileAccessLog
#[derive(Debug, Clone)]
pub struct DeleteFileAccessLogOutput {
    pub deleted: bool,
}

/// Use case for deleting a FileAccessLog
pub struct DeleteFileAccessLogUseCase {
    repository: Arc<FileAccessLogRepository>,
}

impl DeleteFileAccessLogUseCase {
    pub fn new(repository: Arc<FileAccessLogRepository>) -> Self {
        Self { repository }
    }
}

#[async_trait]
impl UseCase for DeleteFileAccessLogUseCase {
    type Input = DeleteFileAccessLogInput;
    type Output = DeleteFileAccessLogOutput;

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

        // <<< CUSTOM PRE-DELETE CHECK START >>>
        // Add custom pre-delete validation here
        // <<< CUSTOM PRE-DELETE CHECK END >>>

        self.repository.delete(input.id).await?;

        Ok(DeleteFileAccessLogOutput { deleted: true })
    }
}