44 lines
1.4 KiB
Go
Executable File
44 lines
1.4 KiB
Go
Executable File
package app
|
|
|
|
import (
|
|
"net/http"
|
|
"strconv"
|
|
|
|
"bindbox-game/internal/code"
|
|
"bindbox-game/internal/pkg/core"
|
|
)
|
|
|
|
type okResponse struct {
|
|
Ok bool `json:"ok"`
|
|
}
|
|
|
|
// SetDefaultUserAddress 设置默认用户地址
|
|
// @Summary 设置默认用户地址
|
|
// @Description 将指定地址设置为当前登录用户的默认地址
|
|
// @Tags APP端.用户
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param user_id path integer true "用户ID"
|
|
// @Param address_id path integer true "地址ID"
|
|
// @Security LoginVerifyToken
|
|
// @Success 200 {object} okResponse
|
|
// @Failure 400 {object} code.Failure "参数错误"
|
|
// @Failure 401 {object} code.Failure "未授权"
|
|
// @Failure 500 {object} code.Failure "服务器内部错误"
|
|
// @Router /api/app/users/{user_id}/addresses/{address_id}/default [put]
|
|
func (h *handler) SetDefaultUserAddress() core.HandlerFunc {
|
|
return func(ctx core.Context) {
|
|
userID := int64(ctx.SessionUserInfo().Id)
|
|
idStr := ctx.Param("address_id")
|
|
addrID, err := strconv.ParseInt(idStr, 10, 64)
|
|
if err != nil || addrID <= 0 {
|
|
ctx.AbortWithError(core.Error(http.StatusBadRequest, code.ParamBindError, "地址ID错误"))
|
|
return
|
|
}
|
|
if err := h.user.SetDefaultAddress(ctx.RequestContext(), userID, addrID); err != nil {
|
|
ctx.AbortWithError(core.Error(http.StatusBadRequest, 10013, err.Error()))
|
|
return
|
|
}
|
|
ctx.Payload(okResponse{Ok: true})
|
|
}
|
|
} |