use std::sync::Arc;
use anyhow::Result;
use async_trait::async_trait;
use super::UseCase;
use crate::domain::entity::UploadSession;
use crate::infrastructure::persistence::UploadSessionRepository;
#[derive(Debug, Clone)]
pub struct CreateUploadSessionInput {
pub bucket_id: Uuid,
pub user_id: Uuid,
pub path: String,
pub filename: String,
pub mime_type: Option<String>,
pub file_size: i64,
pub chunk_size: i32,
pub total_chunks: i32,
pub uploaded_chunks: i32,
pub status: UploadStatus,
pub storage_backend: StorageBackend,
pub completed_parts: Vec<i32>,
pub part_etags: Option<serde_json::Value>,
pub expires_at: DateTime<Utc>,
pub metadata: Option<serde_json::Value>,
}
#[derive(Debug, Clone)]
pub struct CreateUploadSessionOutput {
pub upload_session: UploadSession,
}
pub struct CreateUploadSessionUseCase {
repository: Arc<UploadSessionRepository>,
}
impl CreateUploadSessionUseCase {
pub fn new(repository: Arc<UploadSessionRepository>) -> Self {
Self { repository }
}
}
#[async_trait]
impl UseCase for CreateUploadSessionUseCase {
type Input = CreateUploadSessionInput;
type Output = CreateUploadSessionOutput;
async fn execute(&self, input: Self::Input) -> Result<Self::Output> {
let entity = UploadSession {
id: None,
bucket_id: input.bucket_id,
user_id: input.user_id,
path: input.path,
filename: input.filename,
mime_type: input.mime_type,
file_size: input.file_size,
chunk_size: input.chunk_size,
total_chunks: input.total_chunks,
uploaded_chunks: input.uploaded_chunks,
status: input.status,
storage_backend: input.storage_backend,
completed_parts: input.completed_parts,
part_etags: input.part_etags,
expires_at: input.expires_at,
metadata: input.metadata,
};
let created = self.repository.create(entity).await?;
Ok(CreateUploadSessionOutput { upload_session: created })
}
}