blob: 353a45d6bcfe09647a5ba7185dc163dcddad93d9 [file] [log] [blame]
夜雨声烦5c9d1312025-04-23 17:46:19 +08001package com.example.g8backend.controller;
2
3import com.example.g8backend.entity.Comment;
4import com.example.g8backend.service.ICommentService;
5import org.springframework.beans.factory.annotation.Autowired;
6import org.springframework.web.bind.annotation.*;
7
8import java.util.List;
9
10@RestController
11@RequestMapping("/api/comments")
12public class CommentController {
13
14 @Autowired
15 private ICommentService commentService;
16
17 // 创建评论
18 @PostMapping
19 public void createComment(@RequestParam Long postId, @RequestParam Long userId,
20 @RequestParam String content, @RequestParam(required = false) Long parentCommentId) {
21 commentService.createComment(postId, userId, content, parentCommentId);
22 }
23
24 // 获取某帖子下的所有评论,包括顶级评论及其子评论
25 @GetMapping("/post/{postId}")
26 public List<Comment> getCommentsByPostId(@PathVariable Long postId) {
27 return commentService.getCommentsByPostId(postId);
28 }
29
30 // 删除评论
31 @DeleteMapping("/{commentId}")
32 public void deleteComment(@PathVariable Long commentId) {
33 commentService.deleteComment(commentId);
34 }
35}