use std::sync::Arc;
use anyhow::Result;
use async_trait::async_trait;
use super::UseCase;
use crate::domain::entity::Bucket;
use crate::infrastructure::persistence::BucketRepository;
#[derive(Debug, Clone)]
pub struct CreateBucketInput {
pub name: String,
pub slug: String,
pub description: Option<String>,
pub owner_id: Uuid,
pub bucket_type: BucketType,
pub status: BucketStatus,
pub storage_backend: StorageBackend,
pub root_path: String,
pub file_count: i32,
pub total_size_bytes: i64,
pub max_file_size: Option<i64>,
pub allowed_mime_types: Vec<String>,
pub auto_delete_after_days: Option<i32>,
pub enable_cdn: bool,
pub enable_versioning: bool,
pub enable_deduplication: bool,
pub metadata: serde_json::Value,
}
#[derive(Debug, Clone)]
pub struct CreateBucketOutput {
pub bucket: Bucket,
}
pub struct CreateBucketUseCase {
repository: Arc<BucketRepository>,
}
impl CreateBucketUseCase {
pub fn new(repository: Arc<BucketRepository>) -> Self {
Self { repository }
}
}
#[async_trait]
impl UseCase for CreateBucketUseCase {
type Input = CreateBucketInput;
type Output = CreateBucketOutput;
async fn execute(&self, input: Self::Input) -> Result<Self::Output> {
let entity = Bucket {
id: None,
name: input.name,
slug: input.slug,
description: input.description,
owner_id: input.owner_id,
bucket_type: input.bucket_type,
status: input.status,
storage_backend: input.storage_backend,
root_path: input.root_path,
file_count: input.file_count,
total_size_bytes: input.total_size_bytes,
max_file_size: input.max_file_size,
allowed_mime_types: input.allowed_mime_types,
auto_delete_after_days: input.auto_delete_after_days,
enable_cdn: input.enable_cdn,
enable_versioning: input.enable_versioning,
enable_deduplication: input.enable_deduplication,
metadata: input.metadata,
};
let created = self.repository.create(entity).await?;
Ok(CreateBucketOutput { bucket: created })
}
}