CommentController.java 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package cn.seecoder.web.controller.codereview;
  2. import cn.seecoder.common.exceptions.ServiceException;
  3. import cn.seecoder.web.dto.Response;
  4. import cn.seecoder.web.dto.codereview.CommentCreateVO;
  5. import cn.seecoder.web.dto.codereview.CommentVO;
  6. import cn.seecoder.web.service.codereview.CommentService;
  7. import io.swagger.annotations.Api;
  8. import io.swagger.annotations.ApiImplicitParam;
  9. import io.swagger.annotations.ApiOperation;
  10. import org.springframework.beans.factory.annotation.Autowired;
  11. import org.springframework.web.bind.annotation.GetMapping;
  12. import org.springframework.web.bind.annotation.PathVariable;
  13. import org.springframework.web.bind.annotation.PostMapping;
  14. import org.springframework.web.bind.annotation.RequestBody;
  15. import org.springframework.web.bind.annotation.RequestMapping;
  16. import org.springframework.web.bind.annotation.RestController;
  17. import java.util.List;
  18. /**
  19. * @author Zihe Chen
  20. * @date 2022/1/12
  21. * @description:
  22. */
  23. @Api(tags = "Comment相关Api")
  24. @RestController
  25. @RequestMapping("/comment")
  26. public class CommentController {
  27. private final CommentService commentService;
  28. @Autowired
  29. public CommentController(CommentService commentService) {
  30. this.commentService = commentService;
  31. }
  32. @GetMapping("/{codeReviewId}")
  33. @ApiOperation(value = "获取一个CodeReview的所有评论", httpMethod = "GET")
  34. @ApiImplicitParam(value = "codeReviewId", dataType = "int", paramType = "query")
  35. public Response<List<CommentVO>> list(@PathVariable Integer codeReviewId) throws ServiceException {
  36. return Response.buildSuccess(commentService.list(codeReviewId, false));
  37. }
  38. @GetMapping("/listForFileReview/{fileReviewId}")
  39. @ApiOperation(value = "获取文件评审的所有评论", httpMethod = "GET")
  40. @ApiImplicitParam(value = "fileReview", dataType = "int", paramType = "query")
  41. public Response<List<CommentVO>> listForFileReview(@PathVariable Integer fileReviewId) throws ServiceException {
  42. return Response.buildSuccess(commentService.list(fileReviewId, true));
  43. }
  44. @PostMapping("/create")
  45. @ApiOperation(value = "创建一条新的Comment", httpMethod = "POST")
  46. @ApiImplicitParam(value = "commentCreateVO", dataType = "object", paramType = "body")
  47. public Response<Object> create(@RequestBody CommentCreateVO commentCreateVO) {
  48. commentService.create(commentCreateVO, false);
  49. return Response.buildSuccess();
  50. }
  51. @PostMapping("/createForFileReview")
  52. @ApiOperation(value = "为文件评审创建一条评论", httpMethod = "POST")
  53. @ApiImplicitParam(value = "commentCreateVO", dataType = "object", paramType = "body")
  54. public Response<Object> createForFileReview(@RequestBody CommentCreateVO commentCreateVO) {
  55. commentService.create(commentCreateVO, true);
  56. return Response.buildSuccess();
  57. }
  58. }