mirror of
https://github.com/xinliangnote/go-gin-api.git
synced 2024-04-21 12:31:46 +00:00
- 将 middleware 命名为 interceptor - 将 deploy 命名为 deployments - 移除 pkg/errno - 使用 proposal 目录 - 优化代码
62 lines
1.7 KiB
Go
62 lines
1.7 KiB
Go
package admin
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/xinliangnote/go-gin-api/internal/code"
|
|
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
|
|
"github.com/xinliangnote/go-gin-api/internal/services/admin"
|
|
)
|
|
|
|
type modifyPersonalInfoRequest struct {
|
|
Nickname string `form:"nickname"` // 昵称
|
|
Mobile string `form:"mobile"` // 手机号
|
|
}
|
|
|
|
type modifyPersonalInfoResponse struct {
|
|
Username string `json:"username"` // 用户账号
|
|
}
|
|
|
|
// ModifyPersonalInfo 修改个人信息
|
|
// @Summary 修改个人信息
|
|
// @Description 修改个人信息
|
|
// @Tags API.admin
|
|
// @Accept application/x-www-form-urlencoded
|
|
// @Produce json
|
|
// @Param nickname formData string true "昵称"
|
|
// @Param mobile formData string true "手机号"
|
|
// @Success 200 {object} modifyPersonalInfoResponse
|
|
// @Failure 400 {object} code.Failure
|
|
// @Router /api/admin/modify_personal_info [patch]
|
|
// @Security LoginToken
|
|
func (h *handler) ModifyPersonalInfo() core.HandlerFunc {
|
|
return func(ctx core.Context) {
|
|
req := new(modifyPersonalInfoRequest)
|
|
res := new(modifyPersonalInfoResponse)
|
|
if err := ctx.ShouldBindForm(req); err != nil {
|
|
ctx.AbortWithError(core.Error(
|
|
http.StatusBadRequest,
|
|
code.ParamBindError,
|
|
code.Text(code.ParamBindError)).WithError(err),
|
|
)
|
|
return
|
|
}
|
|
|
|
modifyData := new(admin.ModifyData)
|
|
modifyData.Nickname = req.Nickname
|
|
modifyData.Mobile = req.Mobile
|
|
|
|
if err := h.adminService.ModifyPersonalInfo(ctx, ctx.SessionUserInfo().UserID, modifyData); err != nil {
|
|
ctx.AbortWithError(core.Error(
|
|
http.StatusBadRequest,
|
|
code.AdminModifyPersonalInfoError,
|
|
code.Text(code.AdminModifyPersonalInfoError)).WithError(err),
|
|
)
|
|
return
|
|
}
|
|
|
|
res.Username = ctx.SessionUserInfo().UserName
|
|
ctx.Payload(res)
|
|
}
|
|
}
|