d98e4d59e3
- Add PR assignees API with list, assign, and unassign operations - Add PR check runs API with create, update, list, and delete operations - Implement workspace finding by ID method in core service - Update .gitignore to include .env* files while preserving .env.example - Reorder imports in multiple API files for consistency - Format function calls with proper line breaks across PR-related APIs - Add wiki revision comparison endpoint with proper schema definitions - Integrate new API modules into main application setup - Add health check, readiness probe, and OpenAPI endpoints to main server - Configure session management and dependency injection in main application
142 lines
4.6 KiB
Rust
142 lines
4.6 KiB
Rust
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<i64>,
|
|
pub offset: Option<i64>,
|
|
}
|
|
|
|
/// 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<Vec<PrAssignee>>),
|
|
(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<AppService>,
|
|
session: Session,
|
|
path: web::Path<PrPath>,
|
|
query: web::Query<QP>,
|
|
) -> Result<HttpResponse, AppError> {
|
|
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<PrAssignee>),
|
|
(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<AppService>,
|
|
session: Session,
|
|
path: web::Path<UserPath>,
|
|
) -> Result<HttpResponse, AppError> {
|
|
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<String>),
|
|
(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<AppService>,
|
|
session: Session,
|
|
path: web::Path<UserPath>,
|
|
) -> Result<HttpResponse, AppError> {
|
|
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())))
|
|
}
|