comment.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. package comment
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "hongze/hongze_yb/controller/response"
  5. reqComment "hongze/hongze_yb/models/request/comment"
  6. commentService "hongze/hongze_yb/services/comment"
  7. userService "hongze/hongze_yb/services/user"
  8. "hongze/hongze_yb/utils"
  9. "strconv"
  10. )
  11. // Comment 发布留言
  12. func Comment(c *gin.Context) {
  13. var req reqComment.ReqComment
  14. if c.ShouldBind(&req) !=nil {
  15. response.Fail("入参错误", c)
  16. return
  17. }
  18. userInfo := userService.GetInfoByClaims(c)
  19. data, err := commentService.Comment(userInfo, req)
  20. if err != nil {
  21. response.Fail(err.Error(),c)
  22. return
  23. }
  24. response.OkData("留言成功", data, c)
  25. return
  26. }
  27. // Delete 删除留言
  28. func Delete(c *gin.Context) {
  29. var req *reqComment.ReqDel
  30. if c.ShouldBind(&req) != nil {
  31. response.Fail("参数异常", c)
  32. return
  33. }
  34. userInfo := userService.GetInfoByClaims(c)
  35. err := commentService.Delete(userInfo, req)
  36. if err != nil {
  37. response.Fail(err.Error(),c)
  38. return
  39. }
  40. response.Ok("删除留言成功", c)
  41. return
  42. }
  43. // HotList 获取精选留言
  44. func HotList(c *gin.Context) {
  45. reqReportId := c.DefaultQuery("report_id", "")
  46. reqReportChapterId := c.DefaultQuery("report_chapter_id", "")
  47. reqOldReportId := c.DefaultQuery("old_report_id", "")
  48. reqOldReportChapterId := c.DefaultQuery("old_report_chapter_id", "")
  49. reqPageIndex := c.DefaultQuery("current_index", "1")
  50. reqPageSize := c.DefaultQuery("page_size", strconv.Itoa(utils.PageSize20))
  51. pageIndex, err := strconv.Atoi(reqPageIndex)
  52. if err != nil {
  53. response.Fail("请输入正确的条数限制", c)
  54. return
  55. }
  56. pageSize, err := strconv.Atoi(reqPageSize)
  57. if err != nil {
  58. response.Fail("请输入正确的页码", c)
  59. return
  60. }
  61. var (
  62. reportId int
  63. reportChapterId int
  64. oldReportId int
  65. oldReportChapterId int
  66. )
  67. if reqReportId != ""{
  68. reportId, err = strconv.Atoi(reqReportId)
  69. if err != nil {
  70. response.Fail("报告ID格式有误", c)
  71. return
  72. }
  73. }
  74. if reqReportChapterId != "" {
  75. reportChapterId, err = strconv.Atoi(reqReportChapterId)
  76. if err != nil {
  77. response.Fail("章节ID格式有误", c)
  78. return
  79. }
  80. }
  81. if reqOldReportId != ""{
  82. oldReportId, err = strconv.Atoi(reqOldReportId)
  83. if err != nil {
  84. response.Fail("老报告ID格式有误", c)
  85. return
  86. }
  87. }
  88. if reqOldReportChapterId != "" {
  89. oldReportChapterId, err = strconv.Atoi(reqOldReportChapterId)
  90. if err != nil {
  91. response.Fail("章节ID格式有误", c)
  92. return
  93. }
  94. }
  95. userinfo := userService.GetInfoByClaims(c)
  96. list, err := commentService.List(userinfo, reportId, reportChapterId, oldReportId,oldReportChapterId,true, pageIndex, pageSize)
  97. if err != nil {
  98. response.Fail(err.Error(), c)
  99. return
  100. }
  101. response.OkData("查询成功", list, c )
  102. return
  103. }
  104. // MyList 获取我的留言
  105. func MyList(c *gin.Context) {
  106. reqReportId := c.DefaultQuery("report_id", "")
  107. reqReportChapterId := c.DefaultQuery("report_chapter_id", "")
  108. reqOldReportId := c.DefaultQuery("old_report_id", "")
  109. reqOldReportChapterId := c.DefaultQuery("old_report_chapter_id", "")
  110. var (
  111. reportId int
  112. reportChapterId int
  113. oldReportId int
  114. oldReportChapterId int
  115. err error
  116. )
  117. if reqReportId != ""{
  118. reportId, err = strconv.Atoi(reqReportId)
  119. if err != nil {
  120. response.Fail("报告ID格式有误", c)
  121. return
  122. }
  123. }
  124. if reqReportChapterId != "" {
  125. reportChapterId, err = strconv.Atoi(reqReportChapterId)
  126. if err != nil {
  127. response.Fail("章节ID格式有误", c)
  128. return
  129. }
  130. if reportId <= 0 {
  131. response.Fail("请输入报告ID", c)
  132. return
  133. }
  134. }
  135. if reqOldReportId != ""{
  136. oldReportId, err = strconv.Atoi(reqOldReportId)
  137. if err != nil {
  138. response.Fail("老报告ID格式有误", c)
  139. return
  140. }
  141. }
  142. if reqOldReportChapterId != "" {
  143. oldReportChapterId, err = strconv.Atoi(reqOldReportChapterId)
  144. if err != nil {
  145. response.Fail("章节ID格式有误", c)
  146. return
  147. }
  148. if oldReportId <= 0 {
  149. response.Fail("请输入报告ID", c)
  150. return
  151. }
  152. }
  153. userinfo := userService.GetInfoByClaims(c)
  154. list, err := commentService.List(userinfo, reportId, reportChapterId, oldReportId,oldReportChapterId, false, 0, 0)
  155. if err != nil {
  156. response.Fail(err.Error(), c)
  157. return
  158. }
  159. response.OkData("查询成功", list, c )
  160. return
  161. }