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:
+10
-3
@@ -4,7 +4,8 @@ use utoipa::IntoParams;
|
||||
|
||||
use crate::api::response::{ApiErrorResponse, ApiResponse};
|
||||
use crate::error::AppError;
|
||||
use crate::models::prs::PullRequest;
|
||||
use crate::models::base_info::{self, UserBaseInfo};
|
||||
use crate::models::prs::PullRequestDetail;
|
||||
use crate::service::AppService;
|
||||
use crate::service::pr::core::CreatePrParams;
|
||||
use crate::session::Session;
|
||||
@@ -51,7 +52,7 @@ pub struct PathParams {
|
||||
content_type = "application/json"
|
||||
),
|
||||
responses(
|
||||
(status = 201, description = "PR created successfully. Returns the newly created PR with full metadata.", body = ApiResponse<PullRequest>),
|
||||
(status = 201, description = "PR created successfully. Returns the newly created PR with full metadata.", body = ApiResponse<PullRequestDetail>),
|
||||
(status = 400, description = "Invalid parameters: empty title, non-existent branch/commit, or invalid fork relationship", body = ApiErrorResponse),
|
||||
(status = 401, description = "Authentication required or session expired", body = ApiErrorResponse),
|
||||
(status = 403, description = "Insufficient permissions (requires Member role or higher)", body = ApiErrorResponse),
|
||||
@@ -77,5 +78,11 @@ pub async fn create(
|
||||
params.into_inner(),
|
||||
)
|
||||
.await?;
|
||||
Ok(HttpResponse::Created().json(ApiResponse::new(pr)))
|
||||
let author_id = pr.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(pr.into_detail(author))))
|
||||
}
|
||||
|
||||
+10
-3
@@ -4,7 +4,8 @@ use utoipa::IntoParams;
|
||||
|
||||
use crate::api::response::{ApiErrorResponse, ApiResponse};
|
||||
use crate::error::AppError;
|
||||
use crate::models::prs::PullRequest;
|
||||
use crate::models::base_info::{self, UserBaseInfo};
|
||||
use crate::models::prs::PullRequestDetail;
|
||||
use crate::service::AppService;
|
||||
use crate::session::Session;
|
||||
|
||||
@@ -29,7 +30,7 @@ pub struct PathParams {
|
||||
operation_id = "prGet",
|
||||
params(PathParams),
|
||||
responses(
|
||||
(status = 200, description = "PR retrieved successfully. Returns complete PR with all metadata.", body = ApiResponse<PullRequest>),
|
||||
(status = 200, description = "PR retrieved successfully. Returns complete PR with all metadata.", body = ApiResponse<PullRequestDetail>),
|
||||
(status = 401, description = "Authentication required or session expired", body = ApiErrorResponse),
|
||||
(status = 403, description = "Insufficient permissions to access this repository", body = ApiErrorResponse),
|
||||
(status = 404, description = "Repository, workspace, or PR not found", body = ApiErrorResponse),
|
||||
@@ -48,5 +49,11 @@ pub async fn get(
|
||||
.pr
|
||||
.pr_get(&session, &path.workspace_name, &path.repo_name, path.number)
|
||||
.await?;
|
||||
Ok(HttpResponse::Ok().json(ApiResponse::new(pr)))
|
||||
let author_id = pr.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(pr.into_detail(author))))
|
||||
}
|
||||
|
||||
+2
-2
@@ -55,7 +55,7 @@ pub struct QP {
|
||||
pub offset: Option<i64>,
|
||||
}
|
||||
|
||||
// ── Repo-level labels ──
|
||||
// Section: Repo-level labels
|
||||
|
||||
/// List PR labels in a repository
|
||||
#[utoipa::path(
|
||||
@@ -189,7 +189,7 @@ pub async fn delete_label(
|
||||
Ok(HttpResponse::Ok().json(ApiResponse::new("Label deleted".to_string())))
|
||||
}
|
||||
|
||||
// ── PR-level label relations ──
|
||||
// Section: PR-level label relations
|
||||
|
||||
/// List labels assigned to a PR
|
||||
#[utoipa::path(
|
||||
|
||||
+16
-3
@@ -4,7 +4,8 @@ use utoipa::IntoParams;
|
||||
|
||||
use crate::api::response::{ApiErrorResponse, ApiResponse};
|
||||
use crate::error::AppError;
|
||||
use crate::models::prs::PullRequest;
|
||||
use crate::models::base_info::{self, UserBaseInfo};
|
||||
use crate::models::prs::PullRequestDetail;
|
||||
use crate::service::AppService;
|
||||
use crate::service::pr::core::PrListFilters;
|
||||
use crate::session::Session;
|
||||
@@ -43,7 +44,7 @@ pub struct QueryParams {
|
||||
operation_id = "prList",
|
||||
params(PathParams, QueryParams),
|
||||
responses(
|
||||
(status = 200, description = "PRs listed successfully. Returns filtered array of PR objects.", body = ApiResponse<Vec<PullRequest>>),
|
||||
(status = 200, description = "PRs listed successfully. Returns filtered array of PR objects.", body = ApiResponse<Vec<PullRequestDetail>>),
|
||||
(status = 401, description = "Authentication required or session expired", body = ApiErrorResponse),
|
||||
(status = 403, description = "Insufficient permissions to access this repository", body = ApiErrorResponse),
|
||||
(status = 404, description = "Repository or workspace not found", body = ApiErrorResponse),
|
||||
@@ -75,5 +76,17 @@ pub async fn list(
|
||||
query.offset.unwrap_or(0),
|
||||
)
|
||||
.await?;
|
||||
Ok(HttpResponse::Ok().json(ApiResponse::new(prs)))
|
||||
let user_ids: Vec<_> = prs.iter().map(|p| p.author_id).collect();
|
||||
let users = base_info::resolve_users(&service.ctx.db, &user_ids).await?;
|
||||
let details: Vec<PullRequestDetail> = prs
|
||||
.into_iter()
|
||||
.map(|p| {
|
||||
let author = users
|
||||
.get(&p.author_id)
|
||||
.cloned()
|
||||
.unwrap_or_else(|| UserBaseInfo::placeholder(p.author_id));
|
||||
p.into_detail(author)
|
||||
})
|
||||
.collect();
|
||||
Ok(HttpResponse::Ok().json(ApiResponse::new(details)))
|
||||
}
|
||||
|
||||
+28
-2
@@ -16,8 +16,10 @@ pub mod merge;
|
||||
pub mod merge_strategy;
|
||||
pub mod reactions;
|
||||
pub mod reopen;
|
||||
pub mod review_requests;
|
||||
pub mod reviews;
|
||||
pub mod subscriptions;
|
||||
pub mod templates;
|
||||
pub mod update;
|
||||
|
||||
use actix_web::web;
|
||||
@@ -25,12 +27,23 @@ use actix_web::web;
|
||||
/// Configure PR-level routes under `/workspaces/{workspace_name}/repos/{repo_name}/prs`
|
||||
pub fn configure(cfg: &mut web::ServiceConfig) {
|
||||
cfg.service(
|
||||
web::scope("/prs")
|
||||
web::scope("")
|
||||
// Repo-level labels
|
||||
.route("/labels", web::get().to(labels::list_labels))
|
||||
.route("/labels", web::post().to(labels::create_label))
|
||||
.route("/labels/{label_id}", web::put().to(labels::update_label))
|
||||
.route("/labels/{label_id}", web::delete().to(labels::delete_label))
|
||||
// Templates
|
||||
.route("/templates", web::get().to(templates::list_templates))
|
||||
.route("/templates", web::post().to(templates::create_template))
|
||||
.route(
|
||||
"/templates/{template_id}",
|
||||
web::put().to(templates::update_template),
|
||||
)
|
||||
.route(
|
||||
"/templates/{template_id}",
|
||||
web::delete().to(templates::delete_template),
|
||||
)
|
||||
// Core
|
||||
.route("", web::get().to(list::list))
|
||||
.route("", web::post().to(create::create))
|
||||
@@ -156,6 +169,19 @@ pub fn configure(cfg: &mut web::ServiceConfig) {
|
||||
"/{number}/subscribe",
|
||||
web::delete().to(subscriptions::unsubscribe),
|
||||
)
|
||||
.route("/{number}/mute", web::put().to(subscriptions::mute)),
|
||||
.route("/{number}/mute", web::put().to(subscriptions::mute))
|
||||
// Review Requests
|
||||
.route(
|
||||
"/{number}/requested_reviewers",
|
||||
web::get().to(review_requests::list_requested_reviewers),
|
||||
)
|
||||
.route(
|
||||
"/{number}/requested_reviewers",
|
||||
web::post().to(review_requests::request_reviewers),
|
||||
)
|
||||
.route(
|
||||
"/{number}/requested_reviewers/{user_id}",
|
||||
web::delete().to(review_requests::remove_requested_reviewer),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,116 @@
|
||||
use actix_web::{HttpResponse, web};
|
||||
use serde::Deserialize;
|
||||
use utoipa::IntoParams;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::api::response::{ApiErrorResponse, ApiResponse};
|
||||
use crate::error::AppError;
|
||||
use crate::models::prs::PrReviewRequest;
|
||||
use crate::service::AppService;
|
||||
use crate::session::Session;
|
||||
|
||||
#[derive(Debug, Deserialize, IntoParams)]
|
||||
pub struct PathParams {
|
||||
pub workspace_name: String,
|
||||
pub repo_name: String,
|
||||
pub number: i64,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, IntoParams)]
|
||||
pub struct ReviewerPathParams {
|
||||
pub workspace_name: String,
|
||||
pub repo_name: String,
|
||||
pub number: i64,
|
||||
pub user_id: Uuid,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, utoipa::ToSchema)]
|
||||
pub struct RequestReviewersBody {
|
||||
pub reviewer_ids: Vec<Uuid>,
|
||||
}
|
||||
|
||||
#[utoipa::path(
|
||||
get,
|
||||
path = "/api/v1/workspaces/{workspace_name}/repos/{repo_name}/prs/{number}/requested_reviewers",
|
||||
tag = "PullRequests",
|
||||
operation_id = "prListRequestedReviewers",
|
||||
params(PathParams),
|
||||
responses(
|
||||
(status = 200, description = "List of requested reviewers", body = ApiResponse<Vec<PrReviewRequest>>),
|
||||
(status = 401, description = "Unauthorized", body = ApiErrorResponse),
|
||||
),
|
||||
security(("session_cookie" = []))
|
||||
)]
|
||||
pub async fn list_requested_reviewers(
|
||||
service: web::Data<AppService>,
|
||||
session: Session,
|
||||
path: web::Path<PathParams>,
|
||||
) -> Result<HttpResponse, AppError> {
|
||||
let result = service
|
||||
.pr
|
||||
.pr_requested_reviewers(&session, &path.workspace_name, &path.repo_name, path.number)
|
||||
.await?;
|
||||
Ok(HttpResponse::Ok().json(ApiResponse::new(result)))
|
||||
}
|
||||
|
||||
#[utoipa::path(
|
||||
post,
|
||||
path = "/api/v1/workspaces/{workspace_name}/repos/{repo_name}/prs/{number}/requested_reviewers",
|
||||
tag = "PullRequests",
|
||||
operation_id = "prRequestReviewers",
|
||||
params(PathParams),
|
||||
request_body(content = RequestReviewersBody),
|
||||
responses(
|
||||
(status = 201, description = "Reviewers requested", body = ApiResponse<Vec<PrReviewRequest>>),
|
||||
(status = 401, description = "Unauthorized", body = ApiErrorResponse),
|
||||
),
|
||||
security(("session_cookie" = []))
|
||||
)]
|
||||
pub async fn request_reviewers(
|
||||
service: web::Data<AppService>,
|
||||
session: Session,
|
||||
path: web::Path<PathParams>,
|
||||
body: web::Json<RequestReviewersBody>,
|
||||
) -> Result<HttpResponse, AppError> {
|
||||
let result = service
|
||||
.pr
|
||||
.pr_request_reviewers(
|
||||
&session,
|
||||
&path.workspace_name,
|
||||
&path.repo_name,
|
||||
path.number,
|
||||
body.reviewer_ids.clone(),
|
||||
)
|
||||
.await?;
|
||||
Ok(HttpResponse::Created().json(ApiResponse::new(result)))
|
||||
}
|
||||
|
||||
#[utoipa::path(
|
||||
delete,
|
||||
path = "/api/v1/workspaces/{workspace_name}/repos/{repo_name}/prs/{number}/requested_reviewers/{user_id}",
|
||||
tag = "PullRequests",
|
||||
operation_id = "prRemoveRequestedReviewer",
|
||||
params(ReviewerPathParams),
|
||||
responses(
|
||||
(status = 200, description = "Reviewer removed", body = ApiResponse<String>),
|
||||
(status = 401, description = "Unauthorized", body = ApiErrorResponse),
|
||||
),
|
||||
security(("session_cookie" = []))
|
||||
)]
|
||||
pub async fn remove_requested_reviewer(
|
||||
service: web::Data<AppService>,
|
||||
session: Session,
|
||||
path: web::Path<ReviewerPathParams>,
|
||||
) -> Result<HttpResponse, AppError> {
|
||||
service
|
||||
.pr
|
||||
.pr_remove_requested_reviewer(
|
||||
&session,
|
||||
&path.workspace_name,
|
||||
&path.repo_name,
|
||||
path.number,
|
||||
path.user_id,
|
||||
)
|
||||
.await?;
|
||||
Ok(HttpResponse::Ok().json(ApiResponse::new("reviewer removed".to_string())))
|
||||
}
|
||||
+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
|
||||
|
||||
@@ -0,0 +1,152 @@
|
||||
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::PrTemplate;
|
||||
use crate::service::AppService;
|
||||
use crate::service::pr::templates::{CreatePrTemplateParams, UpdatePrTemplateParams};
|
||||
use crate::session::Session;
|
||||
|
||||
#[derive(Debug, Deserialize, IntoParams)]
|
||||
pub struct PathParams {
|
||||
pub workspace_name: String,
|
||||
pub repo_name: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, IntoParams)]
|
||||
pub struct TemplatePathParams {
|
||||
pub workspace_name: String,
|
||||
pub repo_name: String,
|
||||
pub template_id: uuid::Uuid,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, IntoParams)]
|
||||
pub struct QueryParams {
|
||||
pub limit: Option<i64>,
|
||||
pub offset: Option<i64>,
|
||||
}
|
||||
|
||||
#[utoipa::path(
|
||||
get,
|
||||
path = "/api/v1/workspaces/{workspace_name}/repos/{repo_name}/prs/templates",
|
||||
tag = "PullRequests",
|
||||
operation_id = "prListTemplates",
|
||||
params(PathParams, QueryParams),
|
||||
responses(
|
||||
(status = 200, description = "List of PR templates", body = ApiResponse<Vec<PrTemplate>>),
|
||||
(status = 401, description = "Unauthorized", body = ApiErrorResponse),
|
||||
),
|
||||
security(("session_cookie" = []))
|
||||
)]
|
||||
pub async fn list_templates(
|
||||
service: web::Data<AppService>,
|
||||
session: Session,
|
||||
path: web::Path<PathParams>,
|
||||
query: web::Query<QueryParams>,
|
||||
) -> Result<HttpResponse, AppError> {
|
||||
let result = service
|
||||
.pr
|
||||
.pr_templates(
|
||||
&session,
|
||||
&path.workspace_name,
|
||||
&path.repo_name,
|
||||
query.limit.unwrap_or(50),
|
||||
query.offset.unwrap_or(0),
|
||||
)
|
||||
.await?;
|
||||
Ok(HttpResponse::Ok().json(ApiResponse::new(result)))
|
||||
}
|
||||
|
||||
#[utoipa::path(
|
||||
post,
|
||||
path = "/api/v1/workspaces/{workspace_name}/repos/{repo_name}/prs/templates",
|
||||
tag = "PullRequests",
|
||||
operation_id = "prCreateTemplate",
|
||||
params(PathParams),
|
||||
request_body(content = CreatePrTemplateParams),
|
||||
responses(
|
||||
(status = 201, description = "Template created", body = ApiResponse<PrTemplate>),
|
||||
(status = 401, description = "Unauthorized", body = ApiErrorResponse),
|
||||
),
|
||||
security(("session_cookie" = []))
|
||||
)]
|
||||
pub async fn create_template(
|
||||
service: web::Data<AppService>,
|
||||
session: Session,
|
||||
path: web::Path<PathParams>,
|
||||
body: web::Json<CreatePrTemplateParams>,
|
||||
) -> Result<HttpResponse, AppError> {
|
||||
let result = service
|
||||
.pr
|
||||
.pr_create_template(
|
||||
&session,
|
||||
&path.workspace_name,
|
||||
&path.repo_name,
|
||||
body.into_inner(),
|
||||
)
|
||||
.await?;
|
||||
Ok(HttpResponse::Created().json(ApiResponse::new(result)))
|
||||
}
|
||||
|
||||
#[utoipa::path(
|
||||
put,
|
||||
path = "/api/v1/workspaces/{workspace_name}/repos/{repo_name}/prs/templates/{template_id}",
|
||||
tag = "PullRequests",
|
||||
operation_id = "prUpdateTemplate",
|
||||
params(TemplatePathParams),
|
||||
request_body(content = UpdatePrTemplateParams),
|
||||
responses(
|
||||
(status = 200, description = "Template updated", body = ApiResponse<PrTemplate>),
|
||||
(status = 401, description = "Unauthorized", body = ApiErrorResponse),
|
||||
),
|
||||
security(("session_cookie" = []))
|
||||
)]
|
||||
pub async fn update_template(
|
||||
service: web::Data<AppService>,
|
||||
session: Session,
|
||||
path: web::Path<TemplatePathParams>,
|
||||
body: web::Json<UpdatePrTemplateParams>,
|
||||
) -> Result<HttpResponse, AppError> {
|
||||
let result = service
|
||||
.pr
|
||||
.pr_update_template(
|
||||
&session,
|
||||
&path.workspace_name,
|
||||
&path.repo_name,
|
||||
path.template_id,
|
||||
body.into_inner(),
|
||||
)
|
||||
.await?;
|
||||
Ok(HttpResponse::Ok().json(ApiResponse::new(result)))
|
||||
}
|
||||
|
||||
#[utoipa::path(
|
||||
delete,
|
||||
path = "/api/v1/workspaces/{workspace_name}/repos/{repo_name}/prs/templates/{template_id}",
|
||||
tag = "PullRequests",
|
||||
operation_id = "prDeleteTemplate",
|
||||
params(TemplatePathParams),
|
||||
responses(
|
||||
(status = 200, description = "Template deleted", body = ApiResponse<String>),
|
||||
(status = 401, description = "Unauthorized", body = ApiErrorResponse),
|
||||
),
|
||||
security(("session_cookie" = []))
|
||||
)]
|
||||
pub async fn delete_template(
|
||||
service: web::Data<AppService>,
|
||||
session: Session,
|
||||
path: web::Path<TemplatePathParams>,
|
||||
) -> Result<HttpResponse, AppError> {
|
||||
service
|
||||
.pr
|
||||
.pr_delete_template(
|
||||
&session,
|
||||
&path.workspace_name,
|
||||
&path.repo_name,
|
||||
path.template_id,
|
||||
)
|
||||
.await?;
|
||||
Ok(HttpResponse::Ok().json(ApiResponse::new("template deleted".to_string())))
|
||||
}
|
||||
Reference in New Issue
Block a user