backbone-bucket 0.2.0

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

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

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

/// Use case for deleting a UploadSession
pub struct DeleteUploadSessionUseCase {
    repository: Arc<UploadSessionRepository>,
}

impl DeleteUploadSessionUseCase {
    pub fn new(repository: Arc<UploadSessionRepository>) -> Self {
        Self { repository }
    }
}

#[async_trait]
impl UseCase for DeleteUploadSessionUseCase {
    type Input = DeleteUploadSessionInput;
    type Output = DeleteUploadSessionOutput;

    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!("UploadSession 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(DeleteUploadSessionOutput { deleted: true })
    }
}