用户,社交接口
Change-Id: I10d13773cbe4bbcf3b69a2038cdf7aa9ba54b6df
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);
+ }
+
+}