use std::sync::Arc;
use anyhow::Result;
use async_trait::async_trait;
use super::UseCase;
use crate::domain::entity::FileComment;
use crate::infrastructure::persistence::FileCommentRepository;
#[derive(Debug, Clone)]
pub struct CreateFileCommentInput {
pub file_id: Uuid,
pub user_id: Uuid,
pub parent_id: Option<Uuid>,
pub content: String,
pub annotation_region: Option<serde_json::Value>,
pub mentions: Vec<Uuid>,
pub resolved: bool,
pub resolved_by: Option<Uuid>,
pub resolved_at: Option<DateTime<Utc>>,
pub metadata: Option<serde_json::Value>,
}
#[derive(Debug, Clone)]
pub struct CreateFileCommentOutput {
pub file_comment: FileComment,
}
pub struct CreateFileCommentUseCase {
repository: Arc<FileCommentRepository>,
}
impl CreateFileCommentUseCase {
pub fn new(repository: Arc<FileCommentRepository>) -> Self {
Self { repository }
}
}
#[async_trait]
impl UseCase for CreateFileCommentUseCase {
type Input = CreateFileCommentInput;
type Output = CreateFileCommentOutput;
async fn execute(&self, input: Self::Input) -> Result<Self::Output> {
let entity = FileComment {
id: None,
file_id: input.file_id,
user_id: input.user_id,
parent_id: input.parent_id,
content: input.content,
annotation_region: input.annotation_region,
mentions: input.mentions,
resolved: input.resolved,
resolved_by: input.resolved_by,
resolved_at: input.resolved_at,
metadata: input.metadata,
};
let created = self.repository.create(entity).await?;
Ok(CreateFileCommentOutput { file_comment: created })
}
}