Some checks failed
Build docker and publish / linux (1.24.5) (push) Failing after 31s
refactor(api/user): 重构用户相关接口使用token验证替代user_id路径参数 docs: 更新API文档规范,明确私有接口需携带token及返回字段要求 fix(service/user): 避免写入未使用字段的零值导致MySQL校验错误 style: 统一格式化部分代码缩进和导入顺序 chore: 更新DS_Store等IDE配置文件
85 lines
2.6 KiB
Go
85 lines
2.6 KiB
Go
package app
|
||
|
||
import (
|
||
"net/http"
|
||
|
||
"bindbox-game/internal/code"
|
||
"bindbox-game/internal/pkg/core"
|
||
"bindbox-game/internal/pkg/validation"
|
||
"bindbox-game/internal/repository/mysql/model"
|
||
)
|
||
|
||
type listPointsRequest struct {
|
||
Page int `form:"page"`
|
||
PageSize int `form:"page_size"`
|
||
}
|
||
type listPointsResponse struct {
|
||
Page int `json:"page"`
|
||
PageSize int `json:"page_size"`
|
||
Total int64 `json:"total"`
|
||
List []*model.UserPointsLedger `json:"list"`
|
||
}
|
||
type pointsBalanceResponse struct {
|
||
Balance int64 `json:"balance"`
|
||
}
|
||
|
||
// ListUserPoints 查看用户积分记录
|
||
// @Summary 查看用户积分记录
|
||
// @Description 查看用户积分流水记录
|
||
// @Tags APP端.用户
|
||
// @Accept json
|
||
// @Produce json
|
||
// @Param user_id path integer true "用户ID"
|
||
// @Security LoginVerifyToken
|
||
// @Param page query int true "页码" default(1)
|
||
// @Param page_size query int true "每页数量,最多100" default(20)
|
||
// @Success 200 {object} listPointsResponse
|
||
// @Failure 400 {object} code.Failure
|
||
// @Router /api/app/users/{user_id}/points [get]
|
||
func (h *handler) ListUserPoints() core.HandlerFunc {
|
||
return func(ctx core.Context) {
|
||
req := new(listPointsRequest)
|
||
rsp := new(listPointsResponse)
|
||
if err := ctx.ShouldBindForm(req); err != nil {
|
||
ctx.AbortWithError(core.Error(http.StatusBadRequest, code.ParamBindError, validation.Error(err)))
|
||
return
|
||
}
|
||
userID := int64(ctx.SessionUserInfo().Id)
|
||
items, total, err := h.user.ListPointsLedger(ctx.RequestContext(), userID, req.Page, req.PageSize)
|
||
if err != nil {
|
||
ctx.AbortWithError(core.Error(http.StatusBadRequest, 10004, err.Error()))
|
||
return
|
||
}
|
||
rsp.Page = req.Page
|
||
rsp.PageSize = req.PageSize
|
||
rsp.Total = total
|
||
rsp.List = items
|
||
ctx.Payload(rsp)
|
||
}
|
||
}
|
||
|
||
// GetUserPointsBalance 查看用户积分余额
|
||
// @Summary 查看用户积分余额
|
||
// @Description 查看用户积分余额(过滤过期积分)
|
||
// @Tags APP端.用户
|
||
// @Accept json
|
||
// @Produce json
|
||
// @Param user_id path integer true "用户ID"
|
||
// @Security LoginVerifyToken
|
||
// @Success 200 {object} pointsBalanceResponse
|
||
// @Failure 400 {object} code.Failure
|
||
// @Router /api/app/users/{user_id}/points/balance [get]
|
||
func (h *handler) GetUserPointsBalance() core.HandlerFunc {
|
||
return func(ctx core.Context) {
|
||
rsp := new(pointsBalanceResponse)
|
||
userID := int64(ctx.SessionUserInfo().Id)
|
||
total, err := h.user.GetPointsBalance(ctx.RequestContext(), userID)
|
||
if err != nil {
|
||
ctx.AbortWithError(core.Error(http.StatusBadRequest, 10005, err.Error()))
|
||
return
|
||
}
|
||
rsp.Balance = total
|
||
ctx.Payload(rsp)
|
||
}
|
||
}
|