comment

Change-Id: Iafdf1c3e19b18faa75e96fde1acad93fda6f77f0
diff --git a/src/main/java/com/example/g8backend/controller/CommentController.java b/src/main/java/com/example/g8backend/controller/CommentController.java
new file mode 100644
index 0000000..353a45d
--- /dev/null
+++ b/src/main/java/com/example/g8backend/controller/CommentController.java
@@ -0,0 +1,35 @@
+package com.example.g8backend.controller;
+
+import com.example.g8backend.entity.Comment;
+import com.example.g8backend.service.ICommentService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+
+@RestController
+@RequestMapping("/api/comments")
+public class CommentController {
+
+    @Autowired
+    private ICommentService commentService;
+
+    // 创建评论
+    @PostMapping
+    public void createComment(@RequestParam Long postId, @RequestParam Long userId,
+                              @RequestParam String content, @RequestParam(required = false) Long parentCommentId) {
+        commentService.createComment(postId, userId, content, parentCommentId);
+    }
+
+    // 获取某帖子下的所有评论,包括顶级评论及其子评论
+    @GetMapping("/post/{postId}")
+    public List<Comment> getCommentsByPostId(@PathVariable Long postId) {
+        return commentService.getCommentsByPostId(postId);
+    }
+
+    // 删除评论
+    @DeleteMapping("/{commentId}")
+    public void deleteComment(@PathVariable Long commentId) {
+        commentService.deleteComment(commentId);
+    }
+}