CommentController.java 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. package com.webchat.act.controller;
  2. import com.webchat.act.service.CommentService;
  3. import com.webchat.common.bean.APIPageResponseBean;
  4. import com.webchat.common.bean.APIResponseBean;
  5. import com.webchat.common.bean.APIResponseBeanUtil;
  6. import com.webchat.common.helper.SessionHelper;
  7. import com.webchat.domain.vo.request.CommentSaveVO;
  8. import com.webchat.domain.vo.response.CommentResponseVO;
  9. import com.webchat.rmi.act.ICommentClient;
  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.RequestParam;
  16. import org.springframework.web.bind.annotation.RestController;
  17. import java.util.List;
  18. @RestController
  19. public class CommentController implements ICommentClient {
  20. @Autowired
  21. private CommentService commentService;
  22. /**
  23. * 保存评论
  24. * @param vo
  25. * @return
  26. */
  27. @PostMapping("/addComment")
  28. public APIResponseBean<Long> saveComment(@RequestBody CommentSaveVO vo) {
  29. String authorId = SessionHelper.getCurrentUserId();
  30. vo.setAuthorId(authorId);
  31. Long commentId = commentService.saveComment(vo);
  32. return APIResponseBeanUtil.success(commentId);
  33. }
  34. /**
  35. * 删除评论
  36. * @return
  37. */
  38. public APIResponseBean deleteComment(@PathVariable Long id) {
  39. commentService.deleteComment(id, SessionHelper.getCurrentUserId());
  40. return APIResponseBeanUtil.success();
  41. }
  42. public APIResponseBean<Long> topComment(@PathVariable Long commentId) {
  43. commentService.topComment(commentId);
  44. return APIResponseBeanUtil.success("OK");
  45. }
  46. public APIResponseBean<Long> cancelTopComment(@PathVariable Long commentId) {
  47. commentService.cancelTopComment(commentId);
  48. return APIResponseBeanUtil.success("OK");
  49. }
  50. /***
  51. * 查询资源评论列表
  52. * @param resourceId
  53. * @param resourceType
  54. * @param isHot
  55. * @param isNew
  56. * @param pageNo
  57. * @param pageSize
  58. * @return
  59. */
  60. public APIPageResponseBean<List<CommentResponseVO>> queryComments(@RequestParam(value = "resourceId", required = false) Long resourceId,
  61. @RequestParam(value = "resourceType", required = false) String resourceType,
  62. @RequestParam(value = "content", required = false) String content,
  63. @RequestParam(value = "isHot", required = false, defaultValue = "false") Boolean isHot,
  64. @RequestParam(value = "isNew", required = false, defaultValue = "false") Boolean isNew,
  65. @RequestParam(value = "pageNo", required = false, defaultValue = "1") Integer pageNo,
  66. @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize) {
  67. String currentUserId = SessionHelper.getCurrentUserId();
  68. return commentService.queryCommentByCondition(currentUserId, content, resourceId, resourceType, pageNo, pageSize, isHot, isNew);
  69. }
  70. }