refactor(api): reorder imports and update code formatting across repository endpoints
- Reordered actix-web imports to standardize import order - Reordered crate module imports to follow alphabetical ordering - Updated function calls to use multi-line formatting for better readability - Standardized blank lines around documentation comments - Applied consistent formatting to response handling methods - Normalized import organization across all repository-related API files - Improved code consistency and maintainability through standardized formatting - Applied formatting updates to all repository endpoint implementations
This commit is contained in:
@@ -0,0 +1,220 @@
|
||||
use actix_web::{HttpResponse, web};
|
||||
use serde::Deserialize;
|
||||
use utoipa::IntoParams;
|
||||
|
||||
use crate::api::response::{ApiErrorResponse, ApiResponse};
|
||||
use crate::error::AppError;
|
||||
use crate::models::issues::IssueTemplate;
|
||||
use crate::service::AppService;
|
||||
use crate::service::issues::templates::{CreateTemplateParams, UpdateTemplateParams};
|
||||
use crate::session::Session;
|
||||
|
||||
#[derive(Debug, Deserialize, IntoParams)]
|
||||
pub struct PathParams {
|
||||
/// Workspace name (unique identifier)
|
||||
pub workspace_name: String,
|
||||
/// Repository name (unique within the workspace)
|
||||
pub repo_name: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, IntoParams)]
|
||||
pub struct QueryParams {
|
||||
/// Maximum number of templates to return (default: 50, max: 100)
|
||||
pub limit: Option<i64>,
|
||||
/// Number of templates to skip for pagination (default: 0)
|
||||
pub offset: Option<i64>,
|
||||
}
|
||||
|
||||
/// List issue templates in a repository
|
||||
///
|
||||
/// Returns a paginated list of all active issue templates in the repository.
|
||||
/// Templates provide pre-filled content for creating new issues.
|
||||
/// Sorted alphabetically by name.
|
||||
/// Requires read access to the repository.
|
||||
#[utoipa::path(
|
||||
get,
|
||||
path = "/api/v1/workspaces/{workspace_name}/repos/{repo_name}/issues/templates",
|
||||
tag = "Issues",
|
||||
operation_id = "issueListTemplates",
|
||||
params(PathParams, QueryParams),
|
||||
responses(
|
||||
(status = 200, description = "Templates listed successfully. Returns array of template objects.", body = ApiResponse<Vec<IssueTemplate>>),
|
||||
(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),
|
||||
(status = 500, description = "Internal server error", 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 templates = service
|
||||
.issue
|
||||
.issue_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(templates)))
|
||||
}
|
||||
|
||||
/// Create an issue template
|
||||
///
|
||||
/// Creates a new issue template in the repository.
|
||||
/// Requires at least Member role in the repository.
|
||||
///
|
||||
/// Parameters:
|
||||
/// - name: Template name (required)
|
||||
/// - description: Template description (optional)
|
||||
/// - title_template: Default title for issues (optional, supports placeholders)
|
||||
/// - body_template: Default body content in markdown (required)
|
||||
/// - labels: List of label names to auto-apply (optional)
|
||||
///
|
||||
/// Returns the created template with metadata.
|
||||
#[utoipa::path(
|
||||
post,
|
||||
path = "/api/v1/workspaces/{workspace_name}/repos/{repo_name}/issues/templates",
|
||||
tag = "Issues",
|
||||
operation_id = "issueCreateTemplate",
|
||||
params(PathParams),
|
||||
request_body(
|
||||
content = CreateTemplateParams,
|
||||
description = "Template creation parameters",
|
||||
content_type = "application/json"
|
||||
),
|
||||
responses(
|
||||
(status = 201, description = "Template created successfully. Returns the newly created template.", body = ApiResponse<IssueTemplate>),
|
||||
(status = 400, description = "Invalid parameters: empty name or body template", body = ApiErrorResponse),
|
||||
(status = 401, description = "Authentication required or session expired", body = ApiErrorResponse),
|
||||
(status = 403, description = "Insufficient permissions (requires Member role or higher)", body = ApiErrorResponse),
|
||||
(status = 404, description = "Repository or workspace not found", body = ApiErrorResponse),
|
||||
(status = 500, description = "Internal server error", body = ApiErrorResponse),
|
||||
),
|
||||
security(
|
||||
("session_cookie" = [])
|
||||
)
|
||||
)]
|
||||
pub async fn create_template(
|
||||
service: web::Data<AppService>,
|
||||
session: Session,
|
||||
path: web::Path<PathParams>,
|
||||
params: web::Json<CreateTemplateParams>,
|
||||
) -> Result<HttpResponse, AppError> {
|
||||
let template = service
|
||||
.issue
|
||||
.issue_create_template(
|
||||
&session,
|
||||
&path.workspace_name,
|
||||
&path.repo_name,
|
||||
params.into_inner(),
|
||||
)
|
||||
.await?;
|
||||
Ok(HttpResponse::Created().json(ApiResponse::new(template)))
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, IntoParams)]
|
||||
pub struct TemplatePathParams {
|
||||
/// Workspace name (unique identifier)
|
||||
pub workspace_name: String,
|
||||
/// Repository name (unique within the workspace)
|
||||
pub repo_name: String,
|
||||
/// Template ID (UUID)
|
||||
pub template_id: uuid::Uuid,
|
||||
}
|
||||
|
||||
/// Update an issue template
|
||||
///
|
||||
/// Updates an existing issue template's metadata and content.
|
||||
/// Requires Admin role in the repository.
|
||||
///
|
||||
/// All fields are optional; only provided fields are updated.
|
||||
/// Returns the updated template.
|
||||
#[utoipa::path(
|
||||
put,
|
||||
path = "/api/v1/workspaces/{workspace_name}/repos/{repo_name}/issues/templates/{template_id}",
|
||||
tag = "Issues",
|
||||
operation_id = "issueUpdateTemplate",
|
||||
params(TemplatePathParams),
|
||||
request_body(
|
||||
content = UpdateTemplateParams,
|
||||
description = "Template update parameters (all fields optional)",
|
||||
content_type = "application/json"
|
||||
),
|
||||
responses(
|
||||
(status = 200, description = "Template updated successfully. Returns the updated template.", body = ApiResponse<IssueTemplate>),
|
||||
(status = 401, description = "Authentication required or session expired", body = ApiErrorResponse),
|
||||
(status = 403, description = "Insufficient permissions (requires Admin role)", body = ApiErrorResponse),
|
||||
(status = 404, description = "Repository, workspace, or template not found", body = ApiErrorResponse),
|
||||
(status = 500, description = "Internal server error", body = ApiErrorResponse),
|
||||
),
|
||||
security(
|
||||
("session_cookie" = [])
|
||||
)
|
||||
)]
|
||||
pub async fn update_template(
|
||||
service: web::Data<AppService>,
|
||||
session: Session,
|
||||
path: web::Path<TemplatePathParams>,
|
||||
params: web::Json<UpdateTemplateParams>,
|
||||
) -> Result<HttpResponse, AppError> {
|
||||
let template = service
|
||||
.issue
|
||||
.issue_update_template(
|
||||
&session,
|
||||
&path.workspace_name,
|
||||
&path.repo_name,
|
||||
path.template_id,
|
||||
params.into_inner(),
|
||||
)
|
||||
.await?;
|
||||
Ok(HttpResponse::Ok().json(ApiResponse::new(template)))
|
||||
}
|
||||
|
||||
/// Delete an issue template
|
||||
///
|
||||
/// Permanently removes an issue template from the repository.
|
||||
/// Requires Admin role in the repository.
|
||||
///
|
||||
/// Returns success message on completion.
|
||||
#[utoipa::path(
|
||||
delete,
|
||||
path = "/api/v1/workspaces/{workspace_name}/repos/{repo_name}/issues/templates/{template_id}",
|
||||
tag = "Issues",
|
||||
operation_id = "issueDeleteTemplate",
|
||||
params(TemplatePathParams),
|
||||
responses(
|
||||
(status = 200, description = "Template deleted successfully.", body = ApiResponse<String>),
|
||||
(status = 401, description = "Authentication required or session expired", body = ApiErrorResponse),
|
||||
(status = 403, description = "Insufficient permissions (requires Admin role)", body = ApiErrorResponse),
|
||||
(status = 404, description = "Template not found", body = ApiErrorResponse),
|
||||
(status = 500, description = "Internal server error", body = ApiErrorResponse),
|
||||
),
|
||||
security(
|
||||
("session_cookie" = [])
|
||||
)
|
||||
)]
|
||||
pub async fn delete_template(
|
||||
service: web::Data<AppService>,
|
||||
session: Session,
|
||||
path: web::Path<TemplatePathParams>,
|
||||
) -> Result<HttpResponse, AppError> {
|
||||
service
|
||||
.issue
|
||||
.issue_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