You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
dsl3/controller/CommentController.java

81 lines
3.2 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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<PageResultDTO<CommentDTO>> getComments(CommentVO commentVO) {
//CommentVO为评论的查询条件封装类用来接收前端传递的查询条件
return ResultVO.ok(commentService.listComments(commentVO));
}
@ApiOperation(value = "根据commentId获取回复")// 根据评论ID获取该评论的所有回复列表
@GetMapping("/comments/{commentId}/replies")
public ResultVO<List<ReplyDTO>> listRepliesByCommentId(@PathVariable("commentId") Integer commentId) {
return ResultVO.ok(commentService.listRepliesByCommentId(commentId));
}
@ApiOperation("获取前六个评论")
@GetMapping("/comments/topSix")
public ResultVO<List<CommentDTO>> listTopSixComments() {
return ResultVO.ok(commentService.listTopSixComments());
}
@ApiOperation(value = "查询后台评论")
@GetMapping("/admin/comments")
public ResultVO<PageResultDTO<CommentAdminDTO>> 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<Integer> commentIdList) {
commentService.removeByIds(commentIdList);
return ResultVO.ok();
}
}