backbone-bucket 0.2.0

Bucket Bounded Context: File Storage Module for Backbone Framework
Documentation
//! Create FileShare use case
//!
//! Generated by backbone-schema. Do not edit manually.

use std::sync::Arc;

use anyhow::Result;
use async_trait::async_trait;

use super::UseCase;
use crate::domain::entity::{FileShare, ShareStatus};
use crate::infrastructure::persistence::FileShareRepository;

/// Input for creating a FileShare
#[derive(Debug, Clone)]
pub struct CreateFileShareInput {
    pub file_id: Uuid,
    pub owner_id: Uuid,
    pub token: String,
    pub share_type: ShareType,
    pub permission: SharePermission,
    pub shared_with: Vec<Uuid>,
    pub password_hash: Option<String>,
    pub max_downloads: Option<i32>,
    pub download_count: i32,
    pub expires_at: Option<DateTime<Utc>>,
    pub status: ShareStatus,
    pub revoked_at: Option<DateTime<Utc>>,
    pub revoked_by: Option<Uuid>,
    pub message: Option<String>,
    pub metadata: serde_json::Value,
}

/// Output after creating a FileShare
#[derive(Debug, Clone)]
pub struct CreateFileShareOutput {
    pub file_share: FileShare,
}

/// Use case for creating a new FileShare
pub struct CreateFileShareUseCase {
    repository: Arc<FileShareRepository>,
}

impl CreateFileShareUseCase {
    /// Create a new use case instance
    pub fn new(repository: Arc<FileShareRepository>) -> Self {
        Self { repository }
    }
}

#[async_trait]
impl UseCase for CreateFileShareUseCase {
    type Input = CreateFileShareInput;
    type Output = CreateFileShareOutput;

    async fn execute(&self, input: Self::Input) -> Result<Self::Output> {
        // Create entity from input
        let entity = FileShare {
            id: None,
            file_id: input.file_id,
            owner_id: input.owner_id,
            token: input.token,
            share_type: input.share_type,
            permission: input.permission,
            shared_with: input.shared_with,
            password_hash: input.password_hash,
            max_downloads: input.max_downloads,
            download_count: input.download_count,
            expires_at: input.expires_at,
            status: input.status,
            revoked_at: input.revoked_at,
            revoked_by: input.revoked_by,
            message: input.message,
            metadata: input.metadata,
        };

        // <<< CUSTOM VALIDATION START >>>
        // Add custom validation logic here
        // <<< CUSTOM VALIDATION END >>>

        // Persist entity
        let created = self.repository.create(entity).await?;

        Ok(CreateFileShareOutput { file_share: created })
    }
}