55 lines
1.2 KiB
Go
55 lines
1.2 KiB
Go
package web
|
|
|
|
import (
|
|
"net/http"
|
|
"strconv"
|
|
"videoweb/app/service/commentser"
|
|
"videoweb/pub/common/log"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// CommentList 代理上游 GET /api/app/comment/list(加载更多等)。
|
|
func CommentList(c *gin.Context) {
|
|
objectID, _ := strconv.ParseInt(c.Query("objectId"), 10, 64)
|
|
objectType, _ := strconv.Atoi(c.Query("objectType"))
|
|
pageNum, _ := strconv.Atoi(c.Query("pageNum"))
|
|
pageSize, _ := strconv.Atoi(c.Query("pageSize"))
|
|
sortOrder, _ := strconv.Atoi(c.Query("sortOrder"))
|
|
|
|
q := commentser.ListQuery{
|
|
ObjectID: objectID,
|
|
ObjectType: objectType,
|
|
PageNum: pageNum,
|
|
PageSize: pageSize,
|
|
SortOrder: sortOrder,
|
|
}
|
|
if q.ObjectID <= 0 {
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"code": 1001,
|
|
"msg": "参数错误",
|
|
"tip": "缺少 objectId",
|
|
"data": nil,
|
|
})
|
|
return
|
|
}
|
|
|
|
data, err := commentser.FetchList(c, q)
|
|
if err != nil {
|
|
log.Error("comment list upstream failed", log.E(err))
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"code": 500,
|
|
"msg": "comment list failed",
|
|
"tip": "获取评论失败,请稍后重试",
|
|
"data": nil,
|
|
})
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"code": 200,
|
|
"msg": "success",
|
|
"tip": "成功",
|
|
"data": data,
|
|
})
|
|
}
|