-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.go
36 lines (30 loc) · 1 KB
/
update.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
// Copyright 2023 m01i0ng <alley.ma@qq.com>. All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file. The original repo for
// this file is https://github.com/m01i0ng/mblog.
package user
import (
"github.com/asaskevich/govalidator"
"github.com/gin-gonic/gin"
"github.com/m01i0ng/mblog/internal/pkg/core"
"github.com/m01i0ng/mblog/internal/pkg/errno"
"github.com/m01i0ng/mblog/internal/pkg/log"
v1 "github.com/m01i0ng/mblog/pkg/api/mblog/v1"
)
func (uc *UserController) Update(c *gin.Context) {
log.C(c).Infow("")
var r v1.UpdateUserRequest
if err := c.ShouldBindJSON(&r); err != nil {
core.WriteResponse(c, errno.ErrBind, nil)
return
}
if _, err := govalidator.ValidateStruct(r); err != nil {
core.WriteResponse(c, errno.ErrInvalidParameter.SetMessage(err.Error()), nil)
return
}
if err := uc.b.Users().Update(c, c.Param("name"), &r); err != nil {
core.WriteResponse(c, err, nil)
return
}
core.WriteResponse(c, nil, nil)
}