use actix_web::{HttpResponse, web}; use serde::Deserialize; use utoipa::IntoParams; use crate::api::response::{ApiErrorResponse, ApiResponse}; use crate::error::AppError; use crate::models::prs::PrAssignee; use crate::service::AppService; use crate::session::Session; #[derive(Debug, Deserialize, IntoParams)] pub struct PrPath { /// Workspace name (unique identifier) pub workspace_name: String, /// Repository name (unique within the workspace) pub repo_name: String, /// PR number (unique within the repository) pub number: i64, } #[derive(Debug, Deserialize, IntoParams)] pub struct UserPath { /// Workspace name (unique identifier) pub workspace_name: String, /// Repository name (unique within the workspace) pub repo_name: String, /// PR number (unique within the repository) pub number: i64, /// User ID (UUID) to assign/unassign pub user_id: uuid::Uuid, } #[derive(Debug, Deserialize, IntoParams)] pub struct QP { pub limit: Option, pub offset: Option, } /// List assignees of a PR #[utoipa::path( get, path = "/api/v1/workspaces/{workspace_name}/repos/{repo_name}/prs/{number}/assignees", tag = "Pull Requests", operation_id = "prListAssignees", params(PrPath, QP), responses( (status = 200, description = "Assignees listed.", body = ApiResponse>), (status = 401, description = "Authentication required", body = ApiErrorResponse), (status = 404, description = "PR not found", body = ApiErrorResponse), (status = 500, description = "Internal server error", body = ApiErrorResponse), ), security(("session_cookie" = [])) )] pub async fn list_assignees( service: web::Data, session: Session, path: web::Path, query: web::Query, ) -> Result { let assignees = service .pr .pr_assignees( &session, &path.workspace_name, &path.repo_name, path.number, query.limit.unwrap_or(50), query.offset.unwrap_or(0), ) .await?; Ok(HttpResponse::Ok().json(ApiResponse::new(assignees))) } /// Assign a user to a PR. Assignee is auto-subscribed. #[utoipa::path( post, path = "/api/v1/workspaces/{workspace_name}/repos/{repo_name}/prs/{number}/assignees/{user_id}", tag = "Pull Requests", operation_id = "prAssign", params(UserPath), responses( (status = 201, description = "User assigned.", body = ApiResponse), (status = 401, description = "Authentication required", body = ApiErrorResponse), (status = 403, description = "Insufficient permissions", body = ApiErrorResponse), (status = 404, description = "PR not found", body = ApiErrorResponse), (status = 409, description = "User already assigned", body = ApiErrorResponse), (status = 500, description = "Internal server error", body = ApiErrorResponse), ), security(("session_cookie" = [])) )] pub async fn assign_user( service: web::Data, session: Session, path: web::Path, ) -> Result { let assignee = service .pr .pr_assign( &session, &path.workspace_name, &path.repo_name, path.number, path.user_id, ) .await?; Ok(HttpResponse::Created().json(ApiResponse::new(assignee))) } /// Unassign a user from a PR #[utoipa::path( delete, path = "/api/v1/workspaces/{workspace_name}/repos/{repo_name}/prs/{number}/assignees/{user_id}", tag = "Pull Requests", operation_id = "prUnassign", params(UserPath), responses( (status = 200, description = "User unassigned.", body = ApiResponse), (status = 401, description = "Authentication required", body = ApiErrorResponse), (status = 403, description = "Insufficient permissions", body = ApiErrorResponse), (status = 404, description = "Assignee not found", body = ApiErrorResponse), (status = 500, description = "Internal server error", body = ApiErrorResponse), ), security(("session_cookie" = [])) )] pub async fn unassign_user( service: web::Data, session: Session, path: web::Path, ) -> Result { service .pr .pr_unassign( &session, &path.workspace_name, &path.repo_name, path.number, path.user_id, ) .await?; Ok(HttpResponse::Ok().json(ApiResponse::new("User unassigned".to_string()))) }