package com.aurora.controller; import com.aurora.annotation.AccessLimit; import com.aurora.annotation.OptLog; import com.aurora.model.dto.CommentAdminDTO; import com.aurora.model.dto.CommentDTO; import com.aurora.model.dto.PageResultDTO; import com.aurora.model.dto.ReplyDTO; import com.aurora.service.CommentService; import com.aurora.model.vo.*; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import javax.validation.Valid; import java.util.List; import static com.aurora.constant.OptTypeConstant.*; @Api(tags = "评论模块") @RestController public class CommentController { @Autowired private CommentService commentService;// 使用依赖注入自动装配CommentService,用于处理评论相关的业务逻辑 @AccessLimit(seconds = 60, maxCount = 3)// 自定义注解:访问限制,60秒内同一用户最多允许3次请求(防刷机制) @OptLog(optType = SAVE)//SAVE为操作类型常量 @ApiOperation("添加评论") @PostMapping("/comments/save") public ResultVO saveComment(@Valid @RequestBody CommentVO commentVO) { //CommentVO为评论的参数封装类 commentService.saveComment(commentVO); return ResultVO.ok(); } @ApiOperation("获取评论")// 获取评论列表(通常用于前台展示,支持分页和查询条件) @GetMapping("/comments") // 返回分页结果,包含CommentDTO列表;PageResultDTO为分页结果封装类,包含总条数、当前页数等分页信息 public ResultVO> getComments(CommentVO commentVO) { //CommentVO为评论的查询条件封装类,用来接收前端传递的查询条件 return ResultVO.ok(commentService.listComments(commentVO)); } @ApiOperation(value = "根据commentId获取回复")// 根据评论ID获取该评论的所有回复列表 @GetMapping("/comments/{commentId}/replies") public ResultVO> listRepliesByCommentId(@PathVariable("commentId") Integer commentId) { return ResultVO.ok(commentService.listRepliesByCommentId(commentId)); } @ApiOperation("获取前六个评论") @GetMapping("/comments/topSix") public ResultVO> listTopSixComments() { return ResultVO.ok(commentService.listTopSixComments()); } @ApiOperation(value = "查询后台评论") @GetMapping("/admin/comments") public ResultVO> listCommentBackDTO(ConditionVO conditionVO) { return ResultVO.ok(commentService.listCommentsAdmin(conditionVO)); } @OptLog(optType = UPDATE) @ApiOperation(value = "审核评论") @PutMapping("/admin/comments/review") public ResultVO updateCommentsReview(@Valid @RequestBody ReviewVO reviewVO) { commentService.updateCommentsReview(reviewVO); return ResultVO.ok(); } @OptLog(optType = DELETE) @ApiOperation(value = "删除评论") @DeleteMapping("/admin/comments") public ResultVO deleteComments(@RequestBody List commentIdList) { commentService.removeByIds(commentIdList); return ResultVO.ok(); } }