Files
zhenyi d98e4d59e3 feat(api): implement pull request assignees and check runs endpoints
- 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
2026-06-07 23:01:05 +08:00

144 lines
4.8 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::PrReaction;
use crate::service::AppService;
use crate::service::pr::reactions::CreateReactionParams;
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 ReactionPath {
/// 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,
/// Reaction ID (UUID)
pub reaction_id: uuid::Uuid,
}
#[derive(Debug, Deserialize, IntoParams)]
pub struct QP {
pub limit: Option<i64>,
pub offset: Option<i64>,
}
/// List reactions on a PR
#[utoipa::path(
get,
path = "/api/v1/workspaces/{workspace_name}/repos/{repo_name}/prs/{number}/reactions",
tag = "Pull Requests",
operation_id = "prListReactions",
params(PrPath, QP),
responses(
(status = 200, description = "Reactions listed.", body = ApiResponse<Vec<PrReaction>>),
(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_reactions(
service: web::Data<AppService>,
session: Session,
path: web::Path<PrPath>,
query: web::Query<QP>,
) -> Result<HttpResponse, AppError> {
let reactions = service
.pr
.pr_reactions(
&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(reactions)))
}
/// Add a reaction to a PR
#[utoipa::path(
post,
path = "/api/v1/workspaces/{workspace_name}/repos/{repo_name}/prs/{number}/reactions",
tag = "Pull Requests",
operation_id = "prAddReaction",
params(PrPath),
request_body(content = CreateReactionParams, description = "Reaction parameters", content_type = "application/json"),
responses(
(status = 201, description = "Reaction added.", body = ApiResponse<PrReaction>),
(status = 400, description = "Invalid content or target type", body = ApiErrorResponse),
(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 add_reaction(
service: web::Data<AppService>,
session: Session,
path: web::Path<PrPath>,
params: web::Json<CreateReactionParams>,
) -> Result<HttpResponse, AppError> {
let reaction = service
.pr
.pr_add_reaction(
&session,
&path.workspace_name,
&path.repo_name,
path.number,
params.into_inner(),
)
.await?;
Ok(HttpResponse::Created().json(ApiResponse::new(reaction)))
}
/// Remove a reaction. Only the reaction author can remove it.
#[utoipa::path(
delete,
path = "/api/v1/workspaces/{workspace_name}/repos/{repo_name}/prs/{number}/reactions/{reaction_id}",
tag = "Pull Requests",
operation_id = "prRemoveReaction",
params(ReactionPath),
responses(
(status = 200, description = "Reaction removed.", body = ApiResponse<String>),
(status = 401, description = "Authentication required", 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<AppService>,
session: Session,
path: web::Path<ReactionPath>,
) -> Result<HttpResponse, AppError> {
service
.pr
.pr_remove_reaction(
&session,
&path.workspace_name,
&path.repo_name,
path.number,
path.reaction_id,
)
.await?;
Ok(HttpResponse::Ok().json(ApiResponse::new("Reaction removed".to_string())))
}