blob: 8d61f2353e27cf4bfeef90cccf33cbad4b470986 [file] [log] [blame]
package com.example.g8backend.controller;
import com.example.g8backend.dto.ApiResponse;
import com.example.g8backend.dto.CommentDTO;
import com.example.g8backend.entity.Comment;
import com.example.g8backend.service.ICommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("/api/comments")
public class CommentController {
@Autowired
private ICommentService commentService;
@PostMapping
public ResponseEntity<ApiResponse<CommentDTO>> createComment(@RequestBody CommentDTO commentDTO) {
commentService.createComment(commentDTO);
ApiResponse<CommentDTO> response = ApiResponse.message("评论创建成功");
return ResponseEntity.ok(response);
}
// 获取某帖子下的所有评论,包括顶级评论及其子评论
@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);
}
}