gitdataai/libs/api/issue/comment_reaction.rs
2026-04-15 09:08:09 +08:00

97 lines
3.1 KiB
Rust

use crate::{ApiResponse, error::ApiError};
use actix_web::{HttpResponse, Result, web};
use service::AppService;
use session::Session;
#[utoipa::path(
get,
path = "/api/issue/{project}/issues/{number}/comments/{comment_id}/reactions",
params(
("project" = String, Path),
("number" = i64, Path),
("comment_id" = i64, Path),
),
responses(
(status = 200, description = "List comment reactions", body = ApiResponse<service::issue::ReactionListResponse>),
(status = 401, description = "Unauthorized"),
(status = 404, description = "Not found"),
),
tag = "Issues"
)]
pub async fn issue_comment_reaction_list(
service: web::Data<AppService>,
session: Session,
path: web::Path<(String, i64, i64)>,
) -> Result<HttpResponse, ApiError> {
let (project, issue_number, comment_id) = path.into_inner();
let resp = service
.issue_comment_reaction_list(project, issue_number, comment_id, &session)
.await?;
Ok(ApiResponse::ok(resp).to_response())
}
#[utoipa::path(
post,
path = "/api/issue/{project}/issues/{number}/comments/{comment_id}/reactions",
params(
("project" = String, Path),
("number" = i64, Path),
("comment_id" = i64, Path),
),
request_body = service::issue::ReactionAddRequest,
responses(
(status = 200, description = "Add reaction to comment", body = ApiResponse<service::issue::ReactionResponse>),
(status = 401, description = "Unauthorized"),
(status = 403, description = "Forbidden"),
(status = 404, description = "Not found"),
),
tag = "Issues"
)]
pub async fn issue_comment_reaction_add(
service: web::Data<AppService>,
session: Session,
path: web::Path<(String, i64, i64)>,
body: web::Json<service::issue::ReactionAddRequest>,
) -> Result<HttpResponse, ApiError> {
let (project, issue_number, comment_id) = path.into_inner();
let resp = service
.issue_comment_reaction_add(
project,
issue_number,
comment_id,
body.into_inner(),
&session,
)
.await?;
Ok(ApiResponse::ok(resp).to_response())
}
#[utoipa::path(
delete,
path = "/api/issue/{project}/issues/{number}/comments/{comment_id}/reactions/{reaction}",
params(
("project" = String, Path),
("number" = i64, Path),
("comment_id" = i64, Path),
("reaction" = String, Path),
),
responses(
(status = 200, description = "Remove reaction from comment"),
(status = 401, description = "Unauthorized"),
(status = 403, description = "Forbidden"),
(status = 404, description = "Not found"),
),
tag = "Issues"
)]
pub async fn issue_comment_reaction_remove(
service: web::Data<AppService>,
session: Session,
path: web::Path<(String, i64, i64, String)>,
) -> Result<HttpResponse, ApiError> {
let (project, issue_number, comment_id, reaction) = path.into_inner();
service
.issue_comment_reaction_remove(project, issue_number, comment_id, reaction, &session)
.await?;
Ok(ApiResponse::ok(serde_json::json!({ "success": true })).to_response())
}