fix GET /api/comments/post/{postId} modify return
Change-Id: Iff2dd42b2bb601e36e5a35446e9a80abb182a7e9
diff --git a/src/main/java/com/example/g8backend/controller/CommentController.java b/src/main/java/com/example/g8backend/controller/CommentController.java
index 8d61f23..d861715 100644
--- a/src/main/java/com/example/g8backend/controller/CommentController.java
+++ b/src/main/java/com/example/g8backend/controller/CommentController.java
@@ -25,15 +25,24 @@
return ResponseEntity.ok(response);
}
- // 获取某帖子下的所有评论,包括顶级评论及其子评论
@GetMapping("/post/{postId}")
- public List<Comment> getCommentsByPostId(@PathVariable Long postId) {
- return commentService.getCommentsByPostId(postId);
+ public ApiResponse<List<Comment>> getCommentsByPostId(@PathVariable Long postId) {
+ ApiResponse<List<Comment>> response = new ApiResponse<>();
+ response.setCode(200);
+ response.setMessage("获取评论成功");
+
+ response.setData(commentService.getCommentsByPostId(postId));
+ return response;
}
// 删除评论
@DeleteMapping("/{commentId}")
- public void deleteComment(@PathVariable Long commentId) {
- commentService.deleteComment(commentId);
+ public ApiResponse<String> deleteComment(@PathVariable Long commentId) {
+ try {
+ commentService.deleteComment(commentId);
+ return ApiResponse.message("评论删除成功");
+ } catch (Exception e) {
+ return ApiResponse.error(500, "评论删除失败" + e.getMessage());
+ }
}
}