123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- package comment
- import (
- "github.com/gin-gonic/gin"
- "hongze/hongze_yb/controller/response"
- reqComment "hongze/hongze_yb/models/request/comment"
- commentService "hongze/hongze_yb/services/comment"
- userService "hongze/hongze_yb/services/user"
- "hongze/hongze_yb/utils"
- "strconv"
- )
- // Comment 发布留言
- func Comment(c *gin.Context) {
- var req reqComment.ReqComment
- if c.ShouldBind(&req) !=nil {
- response.Fail("入参错误", c)
- return
- }
- userInfo := userService.GetInfoByClaims(c)
- data, err := commentService.Comment(userInfo, req)
- if err != nil {
- response.Fail(err.Error(),c)
- return
- }
- response.OkData("留言成功", data, c)
- return
- }
- // Delete 删除留言
- func Delete(c *gin.Context) {
- var req *reqComment.ReqDel
- if c.ShouldBind(&req) != nil {
- response.Fail("参数异常", c)
- return
- }
- userInfo := userService.GetInfoByClaims(c)
- err := commentService.Delete(userInfo, req)
- if err != nil {
- response.Fail(err.Error(),c)
- return
- }
- response.Ok("删除留言成功", c)
- return
- }
- // HotList 获取精选留言
- func HotList(c *gin.Context) {
- reqReportId := c.DefaultQuery("report_id", "")
- reqReportChapterId := c.DefaultQuery("report_chapter_id", "")
- reqOldReportId := c.DefaultQuery("old_report_id", "")
- reqOldReportChapterId := c.DefaultQuery("old_report_chapter_id", "")
- reqPageIndex := c.DefaultQuery("current_index", "1")
- reqPageSize := c.DefaultQuery("page_size", strconv.Itoa(utils.PageSize20))
- pageIndex, err := strconv.Atoi(reqPageIndex)
- if err != nil {
- response.Fail("请输入正确的条数限制", c)
- return
- }
- pageSize, err := strconv.Atoi(reqPageSize)
- if err != nil {
- response.Fail("请输入正确的页码", c)
- return
- }
- var (
- reportId int
- reportChapterId int
- oldReportId int
- oldReportChapterId int
- )
- if reqReportId != ""{
- reportId, err = strconv.Atoi(reqReportId)
- if err != nil {
- response.Fail("报告ID格式有误", c)
- return
- }
- }
- if reqReportChapterId != "" {
- reportChapterId, err = strconv.Atoi(reqReportChapterId)
- if err != nil {
- response.Fail("章节ID格式有误", c)
- return
- }
- }
- if reqOldReportId != ""{
- oldReportId, err = strconv.Atoi(reqOldReportId)
- if err != nil {
- response.Fail("老报告ID格式有误", c)
- return
- }
- }
- if reqOldReportChapterId != "" {
- oldReportChapterId, err = strconv.Atoi(reqOldReportChapterId)
- if err != nil {
- response.Fail("章节ID格式有误", c)
- return
- }
- }
- userinfo := userService.GetInfoByClaims(c)
- list, err := commentService.List(userinfo, reportId, reportChapterId, oldReportId,oldReportChapterId,true, pageIndex, pageSize)
- if err != nil {
- response.Fail(err.Error(), c)
- return
- }
- response.OkData("查询成功", list, c )
- return
- }
- // MyList 获取我的留言
- func MyList(c *gin.Context) {
- reqReportId := c.DefaultQuery("report_id", "")
- reqReportChapterId := c.DefaultQuery("report_chapter_id", "")
- reqOldReportId := c.DefaultQuery("old_report_id", "")
- reqOldReportChapterId := c.DefaultQuery("old_report_chapter_id", "")
- var (
- reportId int
- reportChapterId int
- oldReportId int
- oldReportChapterId int
- err error
- )
- if reqReportId != ""{
- reportId, err = strconv.Atoi(reqReportId)
- if err != nil {
- response.Fail("报告ID格式有误", c)
- return
- }
- }
- if reqReportChapterId != "" {
- reportChapterId, err = strconv.Atoi(reqReportChapterId)
- if err != nil {
- response.Fail("章节ID格式有误", c)
- return
- }
- }
- if reqOldReportId != ""{
- oldReportId, err = strconv.Atoi(reqOldReportId)
- if err != nil {
- response.Fail("老报告ID格式有误", c)
- return
- }
- }
- if reqOldReportChapterId != "" {
- oldReportChapterId, err = strconv.Atoi(reqOldReportChapterId)
- if err != nil {
- response.Fail("章节ID格式有误", c)
- return
- }
- }
- userinfo := userService.GetInfoByClaims(c)
- list, err := commentService.MyList(userinfo, reportId, reportChapterId, oldReportId,oldReportChapterId)
- if err != nil {
- response.Fail(err.Error(), c)
- return
- }
- response.OkData("查询成功", list, c )
- return
- }
|