Some checks failed
Build docker and publish / linux (1.24.5) (push) Failing after 25s
feat(admin): 新增工会管理功能 feat(activity): 添加活动管理相关服务 feat(user): 实现用户道具卡和积分管理 feat(guild): 新增工会成员管理功能 fix: 修复数据库连接配置 fix: 修正jwtoken导入路径 fix: 解决端口冲突问题 style: 统一代码格式和注释风格 style: 更新项目常量命名 docs: 添加项目框架和开发规范文档 docs: 更新接口文档注释 chore: 移除无用代码和文件 chore: 更新Makefile和配置文件 chore: 清理日志文件 test: 添加道具卡测试脚本
60 lines
1.8 KiB
Go
60 lines
1.8 KiB
Go
package app
|
|
|
|
import (
|
|
"net/http"
|
|
"strconv"
|
|
|
|
"bindbox-game/internal/code"
|
|
"bindbox-game/internal/pkg/core"
|
|
"bindbox-game/internal/pkg/validation"
|
|
)
|
|
|
|
type modifyUserRequest struct {
|
|
Nickname *string `json:"nickname"`
|
|
Avatar *string `json:"avatar"`
|
|
}
|
|
type userItem struct {
|
|
ID int64 `json:"id"`
|
|
Nickname string `json:"nickname"`
|
|
Avatar string `json:"avatar"`
|
|
InviteCode string `json:"invite_code"`
|
|
InviterID int64 `json:"inviter_id"`
|
|
}
|
|
type modifyUserResponse struct {
|
|
User userItem `json:"user"`
|
|
}
|
|
|
|
// ModifyUser 修改用户信息
|
|
// @Summary 修改用户信息
|
|
// @Description 修改用户昵称与头像
|
|
// @Tags APP端.用户
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param user_id path integer true "用户ID"
|
|
// @Param RequestBody body modifyUserRequest true "请求参数"
|
|
// @Success 200 {object} modifyUserResponse
|
|
// @Failure 400 {object} code.Failure
|
|
// @Router /api/app/users/{user_id} [put]
|
|
func (h *handler) ModifyUser() core.HandlerFunc {
|
|
return func(ctx core.Context) {
|
|
req := new(modifyUserRequest)
|
|
rsp := new(modifyUserResponse)
|
|
if err := ctx.ShouldBindJSON(req); err != nil {
|
|
ctx.AbortWithError(core.Error(http.StatusBadRequest, code.ParamBindError, validation.Error(err)))
|
|
return
|
|
}
|
|
userID, err := strconv.ParseInt(ctx.Param("user_id"), 10, 64)
|
|
if err != nil {
|
|
ctx.AbortWithError(core.Error(http.StatusBadRequest, code.ParamBindError, "未传递用户ID"))
|
|
return
|
|
}
|
|
item, err := h.user.UpdateProfile(ctx.RequestContext(), userID, req.Nickname, req.Avatar)
|
|
if err != nil {
|
|
ctx.AbortWithError(core.Error(http.StatusBadRequest, 10001, err.Error()))
|
|
return
|
|
}
|
|
rsp.User = userItem{ID: item.ID, Nickname: item.Nickname, Avatar: item.Avatar, InviteCode: item.InviteCode, InviterID: item.InviterID}
|
|
ctx.Payload(rsp)
|
|
}
|
|
}
|