comment.go 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. package community
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "hongze/hongze_yb/controller/response"
  5. "hongze/hongze_yb/logic/yb_community_question"
  6. "hongze/hongze_yb/models/request"
  7. responseModel "hongze/hongze_yb/models/response"
  8. "hongze/hongze_yb/services"
  9. userService "hongze/hongze_yb/services/user"
  10. "strconv"
  11. )
  12. // Comment 发布留言
  13. func Comment(c *gin.Context) {
  14. var req request.ReqComment
  15. if c.ShouldBind(&req) != nil {
  16. response.Fail("入参错误", c)
  17. return
  18. }
  19. userInfo := userService.GetInfoByClaims(c)
  20. ybCommunityQuestionComment, err, errMsg := yb_community_question.Comment(userInfo, req.CommunityQuestionID, req.Content, req.SourceAgent, req.IsShowName)
  21. if err != nil {
  22. response.FailMsg(errMsg, err.Error(), c)
  23. return
  24. }
  25. response.OkData("留言成功", responseModel.RespCommunityQuestionCommentAdd{
  26. CommunityQuestionCommentID: ybCommunityQuestionComment.CommunityQuestionCommentID,
  27. }, c)
  28. return
  29. }
  30. // DeleteComment 删除留言
  31. func DeleteComment(c *gin.Context) {
  32. var req *request.ReqDel
  33. if c.ShouldBind(&req) != nil {
  34. response.Fail("参数异常", c)
  35. return
  36. }
  37. userInfo := userService.GetInfoByClaims(c)
  38. err, errMsg := yb_community_question.Delete(userInfo, req.CommunityQuestionCommentID)
  39. if err != nil {
  40. response.FailMsg(errMsg, err.Error(), c)
  41. return
  42. }
  43. response.Ok("删除留言成功", c)
  44. return
  45. }
  46. // HotList 获取精选留言
  47. func HotList(c *gin.Context) {
  48. communityQuestionCommentIDStr := c.DefaultQuery("community_question_comment_id", "")
  49. communityQuestionCommentID, err := strconv.Atoi(communityQuestionCommentIDStr)
  50. if err != nil {
  51. response.Fail("问答id异常", c)
  52. return
  53. }
  54. userinfo := userService.GetInfoByClaims(c)
  55. page := services.GetCurrPageByClaims(c)
  56. pageSize := services.GetPageSizeByClaims(c)
  57. list, total, err, errMsg := yb_community_question.List(userinfo.UserID, communityQuestionCommentID, true, page, pageSize)
  58. if err != nil {
  59. response.FailMsg(errMsg, err.Error(), c)
  60. return
  61. }
  62. response.OkData("查询成功", responseModel.RespCommunityQuestionCommentList{
  63. List: list,
  64. Paging: responseModel.GetPaging(page, pageSize, int(total)),
  65. }, c)
  66. return
  67. }
  68. // MyList 获取我的留言
  69. func MyList(c *gin.Context) {
  70. communityQuestionCommentIDStr := c.DefaultQuery("community_question_comment_id", "")
  71. communityQuestionCommentID, err := strconv.Atoi(communityQuestionCommentIDStr)
  72. if err != nil {
  73. response.Fail("问答id异常", c)
  74. return
  75. }
  76. userinfo := userService.GetInfoByClaims(c)
  77. page := services.GetCurrPageByClaims(c)
  78. pageSize := services.GetPageSizeByClaims(c)
  79. list, total, isShowName, err, errMsg := yb_community_question.MyList(userinfo.UserID, communityQuestionCommentID, page, pageSize)
  80. if err != nil {
  81. response.FailMsg(errMsg, err.Error(), c)
  82. return
  83. }
  84. response.OkData("查询成功", responseModel.RespCommunityQuestionCommentList{
  85. List: list,
  86. Paging: responseModel.GetPaging(page, pageSize, int(total)),
  87. IsShowName: isShowName,
  88. }, c)
  89. return
  90. }
  91. // GetNeedCommentAnonymousUserTips 获取是否 弹出让去设置头像 的提示框
  92. func GetNeedCommentAnonymousUserTips(c *gin.Context) {
  93. userinfo := userService.GetInfoByClaims(c)
  94. ok, err := yb_community_question.GetNeedCommentAnonymousUserTips(userinfo.UserID)
  95. if err != nil {
  96. response.FailMsg("获取失败", err.Error(), c)
  97. return
  98. }
  99. response.OkData("获取成功", ok, c)
  100. }
  101. // SetCommentAnonymousUserTips 设置不再提示 弹出让去设置头像 的提示框
  102. func SetCommentAnonymousUserTips(c *gin.Context) {
  103. userinfo := userService.GetInfoByClaims(c)
  104. err := yb_community_question.SetYbCommentAnonymousUserTips(userinfo.UserID)
  105. if err != nil {
  106. response.FailMsg("设置失败", err.Error(), c)
  107. return
  108. }
  109. response.Ok("设置成功", c)
  110. }