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