backbone-bucket 0.2.0

Bucket Bounded Context: File Storage Module for Backbone Framework
Documentation
//! Create FileComment use case
//!
//! Generated by backbone-schema. Do not edit manually.

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;

/// Input for creating a FileComment
#[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>,
}

/// Output after creating a FileComment
#[derive(Debug, Clone)]
pub struct CreateFileCommentOutput {
    pub file_comment: FileComment,
}

/// Use case for creating a new FileComment
pub struct CreateFileCommentUseCase {
    repository: Arc<FileCommentRepository>,
}

impl CreateFileCommentUseCase {
    /// Create a new use case instance
    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> {
        // Create entity from input
        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,
        };

        // <<< CUSTOM VALIDATION START >>>
        // Add custom validation logic here
        // <<< CUSTOM VALIDATION END >>>

        // Persist entity
        let created = self.repository.create(entity).await?;

        Ok(CreateFileCommentOutput { file_comment: created })
    }
}