blob: f8eb13548807a0345d53c6afb3e2c88c76317031 [file] [log] [blame]
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);
}
}