use crate::{ApiResponse, error::ApiError}; use actix_web::{HttpResponse, Result, web}; use service::AppService; use session::Session; #[utoipa::path( get, path = "/api/issue/{project}/labels", params(("project" = String, Path)), responses( (status = 200, description = "List labels", body = ApiResponse>), (status = 401, description = "Unauthorized"), (status = 404, description = "Not found"), ), tag = "Issues" )] pub async fn label_list( service: web::Data, session: Session, path: web::Path, ) -> Result { let project = path.into_inner(); let resp = service.label_list(project, &session).await?; Ok(ApiResponse::ok(resp).to_response()) } #[utoipa::path( post, path = "/api/issue/{project}/labels", params(("project" = String, Path)), request_body = service::issue::CreateLabelRequest, responses( (status = 200, description = "Create label", body = ApiResponse), (status = 401, description = "Unauthorized"), (status = 403, description = "Forbidden"), (status = 404, description = "Not found"), ), tag = "Issues" )] pub async fn label_create( service: web::Data, session: Session, path: web::Path, body: web::Json, ) -> Result { let project = path.into_inner(); let resp = service .label_create(project, body.into_inner(), &session) .await?; Ok(ApiResponse::ok(resp).to_response()) } #[utoipa::path( delete, path = "/api/issue/{project}/labels/{label_id}", params( ("project" = String, Path), ("label_id" = i64, Path), ), responses( (status = 200, description = "Delete label"), (status = 401, description = "Unauthorized"), (status = 403, description = "Forbidden"), (status = 404, description = "Not found"), ), tag = "Issues" )] pub async fn label_delete( service: web::Data, session: Session, path: web::Path<(String, i64)>, ) -> Result { let (project, label_id) = path.into_inner(); service.label_delete(project, label_id, &session).await?; Ok(ApiResponse::ok(serde_json::json!({ "success": true })).to_response()) }