use std::sync::Arc;
use anyhow::{Result, anyhow};
use async_trait::async_trait;
use uuid::Uuid;
use super::UseCase;
use crate::domain::entity::UploadSession;
use crate::infrastructure::persistence::UploadSessionRepository;
#[derive(Debug, Clone)]
pub struct GetUploadSessionInput {
pub id: Uuid,
}
#[derive(Debug, Clone)]
pub struct GetUploadSessionOutput {
pub upload_session: UploadSession,
}
pub struct GetUploadSessionUseCase {
repository: Arc<UploadSessionRepository>,
}
impl GetUploadSessionUseCase {
pub fn new(repository: Arc<UploadSessionRepository>) -> Self {
Self { repository }
}
}
#[async_trait]
impl UseCase for GetUploadSessionUseCase {
type Input = GetUploadSessionInput;
type Output = GetUploadSessionOutput;
async fn execute(&self, input: Self::Input) -> Result<Self::Output> {
let entity = self.repository.find_by_id(input.id).await?
.ok_or_else(|| anyhow!("UploadSession not found"))?;
Ok(GetUploadSessionOutput { upload_session: entity })
}
}