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::Issue; use crate::service::AppService; use crate::service::issues::core::UpdateIssueParams; 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, } /// Update an issue /// /// Updates an existing issue's metadata such as title, body, priority, visibility, due date, and milestone. /// Requires write access to the issue (author or workspace member). /// /// All fields are optional; only provided fields are updated. /// Returns the updated issue with full metadata. #[utoipa::path( put, path = "/api/v1/workspaces/{workspace_name}/issues/{number}", tag = "Issues", operation_id = "issueUpdate", params(PathParams), request_body( content = UpdateIssueParams, description = "Issue update parameters (all fields optional)", content_type = "application/json" ), responses( (status = 200, description = "Issue updated successfully. Returns the updated issue with full metadata.", body = ApiResponse), (status = 400, description = "Invalid parameters: invalid priority, visibility, or milestone", body = ApiErrorResponse), (status = 401, description = "Authentication required or session expired", body = ApiErrorResponse), (status = 403, description = "Insufficient permissions to edit this issue", body = ApiErrorResponse), (status = 404, description = "Workspace, issue, or referenced resource not found", body = ApiErrorResponse), (status = 500, description = "Internal server error", body = ApiErrorResponse), ), security( ("session_cookie" = []) ) )] pub async fn update( service: web::Data, session: Session, path: web::Path, params: web::Json, ) -> Result { let issue = service .issue .issue_update( &session, &path.workspace_name, path.number, params.into_inner(), ) .await?; Ok(HttpResponse::Ok().json(ApiResponse::new(issue))) }