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::IssueAssignee; use crate::service::AppService; 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, /// User ID (UUID) to assign pub user_id: uuid::Uuid, } /// Assign a user to an issue /// /// Assigns a workspace member to the given issue. /// Requires write access to the issue (author or workspace member). /// /// Effects: /// - User is assigned to the issue /// - Assignee is automatically subscribed to the issue /// - Issue assignee count is incremented /// /// Returns the created assignment record. #[utoipa::path( post, path = "/api/v1/workspaces/{workspace_name}/issues/{number}/assignees/{user_id}", tag = "Issues", operation_id = "issueAssign", params(PathParams), responses( (status = 201, description = "User assigned successfully. Returns the created assignment record.", body = ApiResponse), (status = 401, description = "Authentication required or session expired", body = ApiErrorResponse), (status = 403, description = "Insufficient permissions to edit this issue", body = ApiErrorResponse), (status = 404, description = "Issue or user not found", body = ApiErrorResponse), (status = 409, description = "User is already assigned to this issue", body = ApiErrorResponse), (status = 500, description = "Internal server error", body = ApiErrorResponse), ), security( ("session_cookie" = []) ) )] pub async fn assign_issue( service: web::Data, session: Session, path: web::Path, ) -> Result { let assignee = service .issue .issue_assign(&session, &path.workspace_name, path.number, path.user_id) .await?; Ok(HttpResponse::Created().json(ApiResponse::new(assignee))) }