| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- package nju.seec.helper.controller;
- import nju.seec.helper.aspect.auth.Auth;
- import nju.seec.helper.controller.response.PageResponse;
- import nju.seec.helper.dto.CommentDTO;
- import nju.seec.helper.dto.LoginUser;
- import nju.seec.helper.service.CommentService;
- import nju.seec.helper.util.JsonUtils;
- import nju.seec.helper.util.enums.UserType;
- import nju.seec.helper.vo.CommentVO;
- import org.springframework.data.domain.Pageable;
- import org.springframework.data.web.PageableDefault;
- import org.springframework.web.bind.annotation.*;
- import javax.validation.Valid;
- /**
- * 评论
- *
- * @author cst
- */
- @RestController
- @RequestMapping("/api/comment")
- public class CommentController {
- private final CommentService commentService;
- public CommentController(CommentService commentService) {
- this.commentService = commentService;
- }
- /**
- * 发表评论
- */
- @Auth(roles = {UserType.TEACHER, UserType.STUDENT}, message = "发表评论")
- @PostMapping
- public CommentVO createComment(LoginUser user,
- @Valid @RequestBody CommentDTO commentDTO) {
- CommentVO commentVO = commentService.createComment(user, commentDTO);
- CommentWebsocket.sendAllMessage(commentDTO.getSlideId(), JsonUtils.toJson(commentVO));
- return commentVO;
- }
- /**
- * 删除评论
- */
- @Auth(roles = {UserType.TEACHER, UserType.STUDENT}, message = "删除评论")
- @DeleteMapping("/{commentId}")
- public void removeComment(LoginUser user,
- @PathVariable Integer commentId) {
- commentService.removeComment(user, commentId);
- }
- /**
- * 教师置顶评论
- */
- @Auth(roles = UserType.TEACHER, message = "置顶评论")
- @PostMapping("/{commentId}/top")
- public void topComment(LoginUser user,
- @PathVariable Integer commentId) {
- commentService.topComment(user, commentId);
- }
- /**
- * 教师取消置顶评论
- */
- @Auth(roles = UserType.TEACHER, message = "取消置顶评论")
- @PostMapping("/{commentId}/unTop")
- public void unTopComment(LoginUser user,
- @PathVariable Integer commentId) {
- commentService.unTopComment(user, commentId);
- }
- /**
- * 取得某一页的评论信息
- */
- @GetMapping("/slide/{slideId}")
- public PageResponse<CommentVO> getComments(@PathVariable Integer slideId,
- @RequestParam(required = false, defaultValue = "1") Integer pageNumber,
- @PageableDefault(Integer.MAX_VALUE) Pageable pageable) {
- return PageResponse.of(commentService.getCommentsBySlideIdAndPageNumber(slideId, pageNumber, pageable));
- }
- }
|