用户

Change-Id: I33150cf6ffdea3bf582023bf540394075d081af9
diff --git a/src/main/java/com/example/myproject/controller/CommentController.java b/src/main/java/com/example/myproject/controller/CommentController.java
new file mode 100644
index 0000000..f8eb135
--- /dev/null
+++ b/src/main/java/com/example/myproject/controller/CommentController.java
@@ -0,0 +1,33 @@
+package com.example.myproject.controller;
+
+import com.example.myproject.entity.Comments;
+import com.example.myproject.service.CommentService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+import java.util.Map;
+
+@RestController
+@RequestMapping("/echo/forum/posts")
+public class CommentController {
+
+    @Autowired
+    private CommentService commentService;
+
+    // 添加评论
+    @PostMapping("/{post_id}/comments")
+    public String addComment(@PathVariable("post_id") Long postId, @RequestBody Comments comment) {
+        // 添加评论
+        commentService.addComment(postId, comment);
+        return "Comment added successfully!";
+    }
+
+    //获取所有评论
+    @GetMapping("/{post_id}/getAllComments")
+    public List<Map<String, Object>> getCommentsByPostId(@PathVariable("post_id") Long postId) {
+        // 获取评论并填充用户信息
+        return commentService.getCommentsByPostId(postId);
+    }
+
+}