backbone-bucket 0.2.1

Bucket Bounded Context: File Storage Module for Backbone Framework
Documentation
//! Delete FileVersion 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::FileVersionRepository;

/// Input for deleting a FileVersion
#[derive(Debug, Clone)]
pub struct DeleteFileVersionInput {
    pub id: Uuid,
    /// If true, permanently delete instead of soft delete
    pub hard_delete: bool,
}

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

/// Use case for deleting a FileVersion
pub struct DeleteFileVersionUseCase {
    repository: Arc<FileVersionRepository>,
}

impl DeleteFileVersionUseCase {
    pub fn new(repository: Arc<FileVersionRepository>) -> Self {
        Self { repository }
    }
}

#[async_trait]
impl UseCase for DeleteFileVersionUseCase {
    type Input = DeleteFileVersionInput;
    type Output = DeleteFileVersionOutput;

    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!("FileVersion not found"))?;

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

        if input.hard_delete {
            self.repository.delete(input.id).await?;
        } else {
            self.repository.soft_delete(input.id).await?;
        }

        Ok(DeleteFileVersionOutput { deleted: true })
    }
}