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::IssueReaction; use crate::service::AppService; use crate::service::issues::reactions::CreateIssueReactionParams; use crate::session::Session; #[derive(Debug, Deserialize, IntoParams)] pub struct PathParams { /// Workspace name (unique identifier) pub workspace_name: String, /// Issue number (unique within the workspace) pub number: i64, } #[derive(Debug, Deserialize, IntoParams)] pub struct QueryParams { /// Maximum number of reactions to return (default: 50, max: 100) pub limit: Option, /// Number of reactions to skip for pagination (default: 0) pub offset: Option, } /// List reactions on an issue /// /// Returns a paginated list of all emoji reactions on the given issue. /// Includes reaction content, target type, and user who added each reaction. /// Requires read access to the issue. #[utoipa::path( get, path = "/api/v1/workspaces/{workspace_name}/issues/{number}/reactions", tag = "Issues", operation_id = "issueListReactions", params(PathParams, QueryParams), responses( (status = 200, description = "Reactions listed successfully. Returns array of reaction objects.", body = ApiResponse>), (status = 401, description = "Authentication required or session expired", body = ApiErrorResponse), (status = 403, description = "Insufficient permissions to view this issue", body = ApiErrorResponse), (status = 404, description = "Issue not found", body = ApiErrorResponse), (status = 500, description = "Internal server error", body = ApiErrorResponse), ), security( ("session_cookie" = []) ) )] pub async fn list_reactions( service: web::Data, session: Session, path: web::Path, query: web::Query, ) -> Result { let reactions = service .issue .issue_reactions( &session, &path.workspace_name, path.number, query.limit.unwrap_or(50), query.offset.unwrap_or(0), ) .await?; Ok(HttpResponse::Ok().json(ApiResponse::new(reactions))) } /// Add a reaction to an issue /// /// Adds an emoji reaction to the given issue. /// Requires read access to the issue. /// /// Parameters: /// - content: Reaction content (e.g., "👍", "❤️", "🎉") /// - target_type: Target type for the reaction (defaults to "Issue") /// - target_id: Target ID for reactions on specific comments (optional) /// /// Returns the created reaction. #[utoipa::path( post, path = "/api/v1/workspaces/{workspace_name}/issues/{number}/reactions", tag = "Issues", operation_id = "issueAddReaction", params(PathParams), request_body( content = CreateIssueReactionParams, description = "Reaction creation parameters", content_type = "application/json" ), responses( (status = 201, description = "Reaction added successfully. Returns the created reaction.", body = ApiResponse), (status = 400, description = "Invalid parameters: empty content or invalid target type", body = ApiErrorResponse), (status = 401, description = "Authentication required or session expired", body = ApiErrorResponse), (status = 403, description = "Insufficient permissions", body = ApiErrorResponse), (status = 404, description = "Issue not found", body = ApiErrorResponse), (status = 500, description = "Internal server error", body = ApiErrorResponse), ), security( ("session_cookie" = []) ) )] pub async fn add_reaction( service: web::Data, session: Session, path: web::Path, params: web::Json, ) -> Result { let reaction = service .issue .issue_add_reaction( &session, &path.workspace_name, path.number, params.into_inner(), ) .await?; Ok(HttpResponse::Created().json(ApiResponse::new(reaction))) } #[derive(Debug, Deserialize, IntoParams)] pub struct ReactionPathParams { /// Workspace name (unique identifier) pub workspace_name: String, /// Issue number (unique within the workspace) pub number: i64, /// Reaction ID (UUID) pub reaction_id: uuid::Uuid, } /// Remove a reaction from an issue /// /// Removes a previously added reaction. Only the user who added the reaction can remove it. /// Requires read access to the issue. /// /// Returns success message on completion. #[utoipa::path( delete, path = "/api/v1/workspaces/{workspace_name}/issues/{number}/reactions/{reaction_id}", tag = "Issues", operation_id = "issueRemoveReaction", params(ReactionPathParams), responses( (status = 200, description = "Reaction removed successfully.", body = ApiResponse), (status = 401, description = "Authentication required or session expired", body = ApiErrorResponse), (status = 403, description = "Cannot remove another user's reaction", body = ApiErrorResponse), (status = 404, description = "Reaction not found", body = ApiErrorResponse), (status = 500, description = "Internal server error", body = ApiErrorResponse), ), security( ("session_cookie" = []) ) )] pub async fn remove_reaction( service: web::Data, session: Session, path: web::Path, ) -> Result { service .issue .issue_remove_reaction( &session, &path.workspace_name, path.number, path.reaction_id, ) .await?; Ok(HttpResponse::Ok().json(ApiResponse::new("Reaction removed".to_string()))) }