62 lines
2.2 KiB
Go
62 lines
2.2 KiB
Go
package app
|
||
|
||
import (
|
||
"net/http"
|
||
|
||
"bindbox-game/internal/code"
|
||
"bindbox-game/internal/pkg/core"
|
||
"bindbox-game/internal/pkg/validation"
|
||
usersvc "bindbox-game/internal/service/user"
|
||
)
|
||
|
||
type listInventoryRequest struct {
|
||
Page int `form:"page"`
|
||
PageSize int `form:"page_size"`
|
||
Status int32 `form:"status"`
|
||
}
|
||
|
||
type listInventoryResponse struct {
|
||
Page int `json:"page"`
|
||
PageSize int `json:"page_size"`
|
||
Total int64 `json:"total"`
|
||
List []*usersvc.AggregatedInventory `json:"list"`
|
||
}
|
||
|
||
// ListUserInventory 获取用户资产列表
|
||
// 功能描述: 获取 APP 端当前登录用户的资产记录(user_inventory),并补充商品名称与图片
|
||
// 参数说明: 路径参数 user_id 仅为路由占位,实际以登录态用户ID为准;query 参数 page/page_size 为分页
|
||
// 返回值: core.HandlerFunc,成功返回 listInventoryResponse,失败返回统一错误结构
|
||
// @Summary 获取用户资产列表
|
||
// @Description 获取 APP 端当前登录用户在 user_inventory 的资产记录,支持分页
|
||
// @Tags APP端.用户
|
||
// @Accept json
|
||
// @Produce json
|
||
// @Param user_id path integer true "用户ID"
|
||
// @Security LoginVerifyToken
|
||
// @Param page query int false "页码,默认1"
|
||
// @Param page_size query int false "每页数量,最多100,默认20"
|
||
// @Success 200 {object} listInventoryResponse
|
||
// @Failure 400 {object} code.Failure
|
||
// @Router /api/app/users/{user_id}/inventory [get]
|
||
func (h *handler) ListUserInventory() core.HandlerFunc {
|
||
return func(ctx core.Context) {
|
||
req := new(listInventoryRequest)
|
||
rsp := new(listInventoryResponse)
|
||
if err := ctx.ShouldBindForm(req); err != nil {
|
||
ctx.AbortWithError(core.Error(http.StatusBadRequest, code.ParamBindError, validation.Error(err)))
|
||
return
|
||
}
|
||
userID := int64(ctx.SessionUserInfo().Id)
|
||
rows, total, err := h.user.ListInventoryAggregated(ctx.RequestContext(), userID, req.Page, req.PageSize, req.Status)
|
||
if err != nil {
|
||
ctx.AbortWithError(core.Error(http.StatusBadRequest, 10010, err.Error()))
|
||
return
|
||
}
|
||
rsp.Page = req.Page
|
||
rsp.PageSize = req.PageSize
|
||
rsp.Total = total
|
||
rsp.List = rows
|
||
ctx.Payload(rsp)
|
||
}
|
||
}
|