60 lines
1.3 KiB
Go
60 lines
1.3 KiB
Go
|
package controller
|
||
|
|
||
|
import (
|
||
|
"github.com/gin-gonic/gin"
|
||
|
"go.uber.org/zap"
|
||
|
"net/http"
|
||
|
"youtu_ecpm/api/gin/service"
|
||
|
"youtu_ecpm/dao/query"
|
||
|
)
|
||
|
|
||
|
type RankingList struct {
|
||
|
Controller
|
||
|
appUser *service.AppUserInfo
|
||
|
ranking *service.RankingList
|
||
|
logger *zap.Logger
|
||
|
}
|
||
|
|
||
|
func NewRankingList(logger *zap.Logger, q *query.Query) *RankingList {
|
||
|
return &RankingList{appUser: service.NewAppUserInfo(q), logger: logger}
|
||
|
}
|
||
|
|
||
|
func (ctl *RankingList) GetRankingList(c *gin.Context) {
|
||
|
var req struct {
|
||
|
AppId uint32 `json:"app_id" binding:"required"`
|
||
|
}
|
||
|
if err := c.ShouldBind(&req); err != nil {
|
||
|
ctl.ResponseErr(c, err)
|
||
|
return
|
||
|
}
|
||
|
res, err := ctl.ranking.GetRankingList(c, req.AppId)
|
||
|
if err != nil {
|
||
|
ctl.logger.Sugar().Error("获取", zap.Error(err))
|
||
|
ctl.ResponseErr(c, err)
|
||
|
return
|
||
|
}
|
||
|
c.JSON(http.StatusOK, res)
|
||
|
}
|
||
|
|
||
|
func (ctl *RankingList) SetScore(c *gin.Context) {
|
||
|
var req struct {
|
||
|
AppId uint32 `json:"app_id" binding:"required"`
|
||
|
Score uint32 `json:"score" binding:"required"`
|
||
|
UserId uint64 `json:"user_id" binding:"required"`
|
||
|
}
|
||
|
if err := c.ShouldBind(&req); err != nil {
|
||
|
ctl.ResponseErrParam(c)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
err := ctl.ranking.SetScore(c, req.AppId, req.UserId, req.Score)
|
||
|
if err != nil {
|
||
|
ctl.logger.Sugar().Error("设置分数失败", zap.Error(err))
|
||
|
ctl.ResponseErr(c, err)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
ctl.ResponseOk(c)
|
||
|
return
|
||
|
}
|