use std::sync::Arc;
use anyhow::Result;
use async_trait::async_trait;
use super::UseCase;
use crate::domain::entity::FileLock;
use crate::infrastructure::persistence::FileLockRepository;
#[derive(Debug, Clone)]
pub struct CreateFileLockInput {
pub file_id: Uuid,
pub user_id: Uuid,
pub locked_at: DateTime<Utc>,
pub expires_at: DateTime<Utc>,
pub refreshed_at: Option<DateTime<Utc>>,
pub metadata: Option<serde_json::Value>,
}
#[derive(Debug, Clone)]
pub struct CreateFileLockOutput {
pub file_lock: FileLock,
}
pub struct CreateFileLockUseCase {
repository: Arc<FileLockRepository>,
}
impl CreateFileLockUseCase {
pub fn new(repository: Arc<FileLockRepository>) -> Self {
Self { repository }
}
}
#[async_trait]
impl UseCase for CreateFileLockUseCase {
type Input = CreateFileLockInput;
type Output = CreateFileLockOutput;
async fn execute(&self, input: Self::Input) -> Result<Self::Output> {
let entity = FileLock {
id: None,
file_id: input.file_id,
user_id: input.user_id,
locked_at: input.locked_at,
expires_at: input.expires_at,
refreshed_at: input.refreshed_at,
metadata: input.metadata,
};
let created = self.repository.create(entity).await?;
Ok(CreateFileLockOutput { file_lock: created })
}
}