youtu_ecpm/api/gin/controller/ranking_list.go
2025-01-20 00:14:43 +08:00

60 lines
1.4 KiB
Go

package controller
import (
"gitea.youtukeji.com.cn/xiabin/youtu_ecpm/api/gin/service"
"gitea.youtukeji.com.cn/xiabin/youtu_ecpm/dao/query"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
"net/http"
)
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
}