feat(api): expand API endpoints for repo, PR, user, workspace management
- Add git operation endpoints: archive, compare branches, diff, tree, repository extras - Add repo endpoints: contributors, delete fork, get branch/commit status/deploy key/invitation/member/release/tag/webhook, topics, release assets, webhook deliveries/retry - Add PR endpoints: review requests, templates - Add user endpoints: block/unblock, follow/unfollow, presence, personal access tokens, account restore - Add workspace endpoints: billing history, approvals, domains, integrations, invitations, members, webhooks, restore - Add internal API, notification API, IM API modules - Update route configuration and OpenAPI spec
This commit is contained in:
+41
-9
@@ -4,7 +4,9 @@ use utoipa::IntoParams;
|
||||
|
||||
use crate::api::response::{ApiErrorResponse, ApiResponse};
|
||||
use crate::error::AppError;
|
||||
use crate::models::prs::{PrReview, PrReviewComment};
|
||||
use crate::models::base_info;
|
||||
use crate::models::base_info::UserBaseInfo;
|
||||
use crate::models::prs::{PrReviewComment, PrReviewDetail};
|
||||
use crate::service::AppService;
|
||||
use crate::service::pr::reviews::{
|
||||
AddReplyParams, CreateReviewParams, DismissReviewParams, SubmitReviewParams,
|
||||
@@ -59,7 +61,7 @@ pub struct QP {
|
||||
operation_id = "prListReviews",
|
||||
params(PrPath, QP),
|
||||
responses(
|
||||
(status = 200, description = "Reviews listed.", body = ApiResponse<Vec<PrReview>>),
|
||||
(status = 200, description = "Reviews listed.", body = ApiResponse<Vec<PrReviewDetail>>),
|
||||
(status = 401, description = "Authentication required", body = ApiErrorResponse),
|
||||
(status = 404, description = "PR not found", body = ApiErrorResponse),
|
||||
(status = 500, description = "Internal server error", body = ApiErrorResponse),
|
||||
@@ -83,7 +85,19 @@ pub async fn list_reviews(
|
||||
query.offset.unwrap_or(0),
|
||||
)
|
||||
.await?;
|
||||
Ok(HttpResponse::Ok().json(ApiResponse::new(reviews)))
|
||||
let user_ids: Vec<_> = reviews.iter().map(|r| r.author_id).collect();
|
||||
let users = base_info::resolve_users(&service.ctx.db, &user_ids).await?;
|
||||
let details: Vec<PrReviewDetail> = reviews
|
||||
.into_iter()
|
||||
.map(|r| {
|
||||
let author = users
|
||||
.get(&r.author_id)
|
||||
.cloned()
|
||||
.unwrap_or_else(|| UserBaseInfo::placeholder(r.author_id));
|
||||
r.into_detail(author)
|
||||
})
|
||||
.collect();
|
||||
Ok(HttpResponse::Ok().json(ApiResponse::new(details)))
|
||||
}
|
||||
|
||||
/// Create a review. States: pending, approved, changes_requested, commented. Authors cannot approve their own PRs.
|
||||
@@ -95,7 +109,7 @@ pub async fn list_reviews(
|
||||
params(PrPath),
|
||||
request_body(content = CreateReviewParams, description = "Review parameters", content_type = "application/json"),
|
||||
responses(
|
||||
(status = 201, description = "Review created.", body = ApiResponse<PrReview>),
|
||||
(status = 201, description = "Review created.", body = ApiResponse<PrReviewDetail>),
|
||||
(status = 400, description = "Invalid state or self-approval", body = ApiErrorResponse),
|
||||
(status = 401, description = "Authentication required", body = ApiErrorResponse),
|
||||
(status = 403, description = "Insufficient permissions", body = ApiErrorResponse),
|
||||
@@ -120,7 +134,13 @@ pub async fn create_review(
|
||||
params.into_inner(),
|
||||
)
|
||||
.await?;
|
||||
Ok(HttpResponse::Created().json(ApiResponse::new(review)))
|
||||
let author_id = review.author_id;
|
||||
let users = base_info::resolve_users(&service.ctx.db, &[author_id]).await?;
|
||||
let author = users
|
||||
.get(&author_id)
|
||||
.cloned()
|
||||
.unwrap_or_else(|| UserBaseInfo::placeholder(author_id));
|
||||
Ok(HttpResponse::Created().json(ApiResponse::new(review.into_detail(author))))
|
||||
}
|
||||
|
||||
/// Submit a pending review. Changes its state to approved, changes_requested, or commented.
|
||||
@@ -132,7 +152,7 @@ pub async fn create_review(
|
||||
params(ReviewPath),
|
||||
request_body(content = SubmitReviewParams, description = "Submit parameters", content_type = "application/json"),
|
||||
responses(
|
||||
(status = 200, description = "Review submitted.", body = ApiResponse<PrReview>),
|
||||
(status = 200, description = "Review submitted.", body = ApiResponse<PrReviewDetail>),
|
||||
(status = 400, description = "Invalid state or self-approval", body = ApiErrorResponse),
|
||||
(status = 401, description = "Authentication required", body = ApiErrorResponse),
|
||||
(status = 403, description = "Insufficient permissions", body = ApiErrorResponse),
|
||||
@@ -158,7 +178,13 @@ pub async fn submit_review(
|
||||
params.into_inner(),
|
||||
)
|
||||
.await?;
|
||||
Ok(HttpResponse::Ok().json(ApiResponse::new(review)))
|
||||
let author_id = review.author_id;
|
||||
let users = base_info::resolve_users(&service.ctx.db, &[author_id]).await?;
|
||||
let author = users
|
||||
.get(&author_id)
|
||||
.cloned()
|
||||
.unwrap_or_else(|| UserBaseInfo::placeholder(author_id));
|
||||
Ok(HttpResponse::Ok().json(ApiResponse::new(review.into_detail(author))))
|
||||
}
|
||||
|
||||
/// Dismiss a submitted review. Requires Admin role.
|
||||
@@ -170,7 +196,7 @@ pub async fn submit_review(
|
||||
params(ReviewPath),
|
||||
request_body(content = DismissReviewParams, description = "Dismiss parameters", content_type = "application/json"),
|
||||
responses(
|
||||
(status = 200, description = "Review dismissed.", body = ApiResponse<PrReview>),
|
||||
(status = 200, description = "Review dismissed.", body = ApiResponse<PrReviewDetail>),
|
||||
(status = 401, description = "Authentication required", body = ApiErrorResponse),
|
||||
(status = 403, description = "Insufficient permissions (Admin required)", body = ApiErrorResponse),
|
||||
(status = 404, description = "Review not found or not submitted", body = ApiErrorResponse),
|
||||
@@ -195,7 +221,13 @@ pub async fn dismiss_review(
|
||||
params.into_inner(),
|
||||
)
|
||||
.await?;
|
||||
Ok(HttpResponse::Ok().json(ApiResponse::new(review)))
|
||||
let author_id = review.author_id;
|
||||
let users = base_info::resolve_users(&service.ctx.db, &[author_id]).await?;
|
||||
let author = users
|
||||
.get(&author_id)
|
||||
.cloned()
|
||||
.unwrap_or_else(|| UserBaseInfo::placeholder(author_id));
|
||||
Ok(HttpResponse::Ok().json(ApiResponse::new(review.into_detail(author))))
|
||||
}
|
||||
|
||||
/// List comments for a specific review
|
||||
|
||||
Reference in New Issue
Block a user