bindbox-game/internal/api/user/shipping_groups_app.go

57 lines
1.8 KiB
Go
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package app
import (
"bindbox-game/internal/code"
"bindbox-game/internal/pkg/core"
"bindbox-game/internal/pkg/validation"
"net/http"
usersvc "bindbox-game/internal/service/user"
)
type listShipmentsRequest struct {
Page int `form:"page"`
PageSize int `form:"page_size"`
}
type listShipmentsResponse struct {
Page int `json:"page"`
PageSize int `json:"page_size"`
Total int64 `json:"total"`
List []*usersvc.ShipmentGroup `json:"list"`
}
// @Summary 获取用户发货分组列表
// @Description 按运单号聚合用户的发货记录,支持分页
// @Tags APP端.发货
// @Accept json
// @Produce json
// @Security LoginVerifyToken
// @Param user_id path integer true "用户ID"
// @Param page query int false "页码默认1"
// @Param page_size query int false "每页数量最多100默认20"
// @Success 200 {object} listShipmentsResponse
// @Failure 400 {object} code.Failure
// @Router /api/app/users/{user_id}/shipments [get]
func (h *handler) ListUserShipments() core.HandlerFunc {
return func(ctx core.Context) {
req := new(listShipmentsRequest)
rsp := new(listShipmentsResponse)
if err := ctx.ShouldBindQuery(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.ListUserShipmentGroups(ctx.RequestContext(), userID, req.Page, req.PageSize)
if err != nil {
ctx.AbortWithError(core.Error(http.StatusBadRequest, 10030, err.Error()))
return
}
rsp.Page = req.Page
rsp.PageSize = req.PageSize
rsp.Total = total
rsp.List = rows
ctx.Payload(rsp)
}
}