use actix_web::{HttpResponse, web}; use serde::Deserialize; use utoipa::IntoParams; use crate::api::response::{ApiErrorResponse, ApiResponse}; use crate::error::AppError; use crate::models::issues::IssueComment; use crate::service::AppService; use crate::service::issues::comments::CreateCommentParams; use crate::session::Session; #[derive(Debug, Deserialize, IntoParams)] pub struct PathParams { pub workspace_name: String, pub number: i64, } /// Create a comment on an issue /// /// Adds a new comment to an issue. Users with read access can comment unless the issue is locked /// (in which case only users with write access can comment). /// /// Parameters: /// - body: Comment body in markdown format (required) /// - reply_to_comment_id: ID of parent comment for threaded replies (optional) /// /// Effects: /// - Comment is created and attached to the issue /// - Commenter is automatically subscribed to the issue /// - Issue comment count is incremented /// /// Returns the created comment with metadata. #[utoipa::path( post, path = "/api/v1/workspaces/{workspace_name}/issues/{number}/comments", tag = "Issues", operation_id = "issueCreateComment", params(PathParams), request_body(content = CreateCommentParams, description = "Comment creation parameters", content_type = "application/json"), responses( (status = 201, description = "Comment created successfully.", body = ApiResponse), (status = 400, description = "Invalid parameters: empty body or issue is locked", body = ApiErrorResponse), (status = 401, description = "Authentication required or session expired", body = ApiErrorResponse), (status = 403, description = "Insufficient permissions (issue locked and user lacks write access)", body = ApiErrorResponse), (status = 404, description = "Workspace or issue not found", body = ApiErrorResponse), (status = 500, description = "Internal server error", body = ApiErrorResponse), ), security(("session_cookie" = [])) )] pub async fn create_comment( service: web::Data, session: Session, path: web::Path, params: web::Json, ) -> Result { let comment = service .issue .issue_create_comment( &session, &path.workspace_name, path.number, params.into_inner(), ) .await?; Ok(HttpResponse::Created().json(ApiResponse::new(comment))) }