blob: 8d61f2353e27cf4bfeef90cccf33cbad4b470986 [file] [log] [blame]
夜雨声烦5c9d1312025-04-23 17:46:19 +08001package com.example.g8backend.controller;
2
夜雨声烦af4d3972025-06-08 17:52:16 +08003import com.example.g8backend.dto.ApiResponse;
4import com.example.g8backend.dto.CommentDTO;
夜雨声烦5c9d1312025-04-23 17:46:19 +08005import com.example.g8backend.entity.Comment;
6import com.example.g8backend.service.ICommentService;
7import org.springframework.beans.factory.annotation.Autowired;
夜雨声烦af4d3972025-06-08 17:52:16 +08008import org.springframework.http.ResponseEntity;
夜雨声烦5c9d1312025-04-23 17:46:19 +08009import org.springframework.web.bind.annotation.*;
10
11import java.util.List;
12
13@RestController
14@RequestMapping("/api/comments")
15public class CommentController {
16
17 @Autowired
18 private ICommentService commentService;
19
夜雨声烦af4d3972025-06-08 17:52:16 +080020
夜雨声烦5c9d1312025-04-23 17:46:19 +080021 @PostMapping
夜雨声烦af4d3972025-06-08 17:52:16 +080022 public ResponseEntity<ApiResponse<CommentDTO>> createComment(@RequestBody CommentDTO commentDTO) {
23 commentService.createComment(commentDTO);
24 ApiResponse<CommentDTO> response = ApiResponse.message("评论创建成功");
25 return ResponseEntity.ok(response);
夜雨声烦5c9d1312025-04-23 17:46:19 +080026 }
27
28 // 获取某帖子下的所有评论,包括顶级评论及其子评论
29 @GetMapping("/post/{postId}")
30 public List<Comment> getCommentsByPostId(@PathVariable Long postId) {
31 return commentService.getCommentsByPostId(postId);
32 }
33
34 // 删除评论
35 @DeleteMapping("/{commentId}")
36 public void deleteComment(@PathVariable Long commentId) {
37 commentService.deleteComment(commentId);
38 }
39}