/src/main/java/com/beautifulsoup/chengfeng/controller/community/PostNewsController.java

https://github.com/fuyunwang/ChengFeng1.5 · Java · 142 lines · 106 code · 34 blank · 2 comment · 4 complexity · 4c58c0ae4d4d33898fa2e21e4641903b MD5 · raw file

  1. package com.beautifulsoup.chengfeng.controller.community;
  2. import com.beautifulsoup.chengfeng.common.ResponseResult;
  3. import com.beautifulsoup.chengfeng.controller.vo.PostNewsDetailVo;
  4. import com.beautifulsoup.chengfeng.controller.vo.PostNewsVo;
  5. import com.beautifulsoup.chengfeng.controller.vo.PostReplyVo;
  6. import com.beautifulsoup.chengfeng.controller.vo.PosterVo;
  7. import com.beautifulsoup.chengfeng.pojo.Journalism;
  8. import com.beautifulsoup.chengfeng.pojo.PostNews;
  9. import com.beautifulsoup.chengfeng.service.PostNewsService;
  10. import com.beautifulsoup.chengfeng.service.dto.PostNewsDto;
  11. import com.beautifulsoup.chengfeng.service.dto.PostReplyDto;
  12. import com.beautifulsoup.chengfeng.utils.ParamValidatorUtil;
  13. import io.swagger.annotations.Api;
  14. import io.swagger.annotations.ApiOperation;
  15. import lombok.extern.slf4j.Slf4j;
  16. import org.springframework.beans.factory.annotation.Autowired;
  17. import org.springframework.http.MediaType;
  18. import org.springframework.stereotype.Controller;
  19. import org.springframework.validation.BindingResult;
  20. import org.springframework.web.bind.annotation.*;
  21. import org.springframework.web.multipart.MultipartFile;
  22. import javax.validation.Valid;
  23. import java.util.List;
  24. @Api(value="普通帖子",tags= {"普通帖子Controller"},description = "普通帖子",protocols = "http")
  25. @Slf4j
  26. @Controller
  27. @RequestMapping(value = "/news")
  28. public class PostNewsController {
  29. @Autowired
  30. private PostNewsService postNewsService;
  31. @ApiOperation(value="发新贴",notes="发新帖方法")
  32. @PostMapping(value="/create",produces = MediaType.APPLICATION_JSON_UTF8_VALUE,consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
  33. @ResponseBody
  34. public ResponseResult<PostNewsVo> createPostNews(@Valid @RequestBody PostNewsDto messageDto, BindingResult result){
  35. PostNewsVo vo = postNewsService.createPostNews(messageDto,result);
  36. if(null!=vo) {
  37. return ResponseResult.createBySuccess(vo);
  38. }
  39. return ResponseResult.createByErrorMessage("帖子创建失败");
  40. }
  41. @GetMapping(value = "/all",produces = "application/json;charset=UTF-8")
  42. @ResponseBody
  43. public ResponseResult<List<PostNewsVo>> getAllPostNews(
  44. @RequestParam(value = "pageNum",defaultValue = "1",required = false)Integer pageNum,
  45. @RequestParam(value = "pageSize",defaultValue = "4",required = false)Integer pageSize){
  46. List<PostNewsVo> postNewsByPage= postNewsService.getAllPostNewsByPage(pageNum,pageSize);
  47. return ResponseResult.createBySuccess(postNewsByPage);
  48. }
  49. @GetMapping(value = "/nice",produces = "application/json;charset=UTF-8")
  50. @ResponseBody
  51. public ResponseResult<List<PostNewsVo>> getNicePostNews(
  52. @RequestParam(value = "pageNum",defaultValue = "1",required = false)Integer pageNum,
  53. @RequestParam(value = "pageSize",defaultValue = "4",required = false)Integer pageSize){
  54. List<PostNewsVo> postNewsByPage= postNewsService.getNicePostNewsByPage(pageNum,pageSize);
  55. return ResponseResult.createBySuccess(postNewsByPage);
  56. }
  57. @GetMapping(value = "/detail/{newsId}",produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
  58. @ResponseBody
  59. public ResponseResult<PostNewsDetailVo> getPostNewsDetail(@PathVariable("newsId")Integer newsId){
  60. PostNewsDetailVo postNewsDetail = postNewsService.getPostNewsDetail(newsId);
  61. return ResponseResult.createBySuccess(postNewsDetail);
  62. }
  63. //获取平级回帖列表
  64. @GetMapping(value = "/replys/{newsId}",produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
  65. @ResponseBody
  66. public ResponseResult<List<PostReplyVo>> getPostReplys(@PathVariable("newsId")Integer newsId){
  67. List<PostReplyVo> postNewsVoList=postNewsService.getPostReplysByNewsId(newsId);
  68. return ResponseResult.createBySuccess(postNewsVoList);
  69. }
  70. //递归获取指定回帖的所有子回帖
  71. @GetMapping(value = "/replys/children/{replyId}",produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
  72. @ResponseBody
  73. public ResponseResult<List<PostReplyVo>> getPostReplysChildren(@PathVariable("replyId")Integer replyId){
  74. List<PostReplyVo> postNewsVoList=postNewsService.getPostReplysChildrenById(replyId);
  75. return ResponseResult.createBySuccess(postNewsVoList);
  76. }
  77. @ApiOperation(value="创建回帖",notes="发新回帖方法")
  78. @PostMapping(value="/reply/create",produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
  79. @ResponseBody
  80. public ResponseResult<PostReplyVo> createPostNews(@Valid @RequestBody PostReplyDto postReplyDto,
  81. BindingResult result){
  82. PostReplyVo vo = postNewsService.createNewPostReply(postReplyDto,result);
  83. if(null!=vo) {
  84. return ResponseResult.createBySuccess(vo);
  85. }
  86. return ResponseResult.createByErrorMessage("帖子创建失败");
  87. }
  88. @ApiOperation(value="关注其他人",notes="关注其他人")
  89. @PostMapping(value="/follow/poster/{nickname}",produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
  90. @ResponseBody
  91. public ResponseResult<PosterVo> followPoster(@PathVariable("nickname")String nickname){
  92. PosterVo vo = postNewsService.followPoster(nickname);
  93. if(null!=vo) {
  94. return ResponseResult.createBySuccess(vo);
  95. }
  96. return ResponseResult.createByErrorMessage("关注他人失败");
  97. }
  98. @ApiOperation(value="收藏帖子",notes="收藏帖子")
  99. @PostMapping(value="/collect/{newsId}",produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
  100. @ResponseBody
  101. public ResponseResult<PosterVo> collectPostNews(@PathVariable("newsId")Integer newsId){
  102. PosterVo vo = postNewsService.collectPostNews(newsId);
  103. if(null!=vo) {
  104. return ResponseResult.createBySuccess(vo);
  105. }
  106. return ResponseResult.createByErrorMessage("帖子收藏失败");
  107. }
  108. }