-
Notifications
You must be signed in to change notification settings - Fork 0
/
func_modifypersonalinfo.go
65 lines (55 loc) · 1.75 KB
/
func_modifypersonalinfo.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package admin_handler
import (
"net/http"
"github.com/skyzhouzj/xhframwork/internal/api/service/admin_service"
"github.com/skyzhouzj/xhframwork/internal/pkg/code"
"github.com/skyzhouzj/xhframwork/internal/pkg/core"
"github.com/skyzhouzj/xhframwork/pkg/errno"
"github.com/spf13/cast"
)
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 multipart/form-data
// @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_password [patch]
func (h *handler) ModifyPersonalInfo() core.HandlerFunc {
return func(c core.Context) {
req := new(modifyPersonalInfoRequest)
res := new(modifyPersonalInfoResponse)
if err := c.ShouldBindForm(req); err != nil {
c.AbortWithError(errno.NewError(
http.StatusBadRequest,
code.ParamBindError,
code.Text(code.ParamBindError)).WithErr(err),
)
return
}
userId := cast.ToInt32(c.UserID())
modifyData := new(admin_service.ModifyData)
modifyData.Nickname = req.Nickname
modifyData.Mobile = req.Mobile
if err := h.adminService.ModifyPersonalInfo(c, userId, modifyData); err != nil {
c.AbortWithError(errno.NewError(
http.StatusBadRequest,
code.AdminModifyPersonalInfoError,
code.Text(code.AdminModifyPersonalInfoError)).WithErr(err),
)
return
}
res.Username = c.UserName()
c.Payload(res)
}
}