-
Notifications
You must be signed in to change notification settings - Fork 12
/
profile.go
43 lines (37 loc) · 1.21 KB
/
profile.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
package makeless_go
import (
"github.com/gin-gonic/gin"
"github.com/makeless/makeless-go/http"
"github.com/makeless/makeless-go/model"
"github.com/makeless/makeless-go/struct"
h "net/http"
"sync"
)
func (makeless *Makeless) updateProfile(http makeless_go_http.Http) error {
http.GetRouter().GetEngine().PATCH(
"/api/auth/profile",
http.GetAuthenticator().GetMiddleware().MiddlewareFunc(),
http.EmailVerificationMiddleware(makeless.GetConfig().GetConfiguration().GetEmailVerification()),
func(c *gin.Context) {
var err error
var userId = http.GetAuthenticator().GetAuthUserId(c)
var user = &makeless_go_model.User{
Model: makeless_go_model.Model{Id: userId},
RWMutex: new(sync.RWMutex),
}
var profile = &_struct.Profile{
RWMutex: new(sync.RWMutex),
}
if err = c.ShouldBind(profile); err != nil {
c.AbortWithStatusJSON(h.StatusBadRequest, http.Response(err, nil))
return
}
if user, err = http.GetDatabase().UpdateProfile(http.GetDatabase().GetConnection().WithContext(c), user, profile); err != nil {
c.AbortWithStatusJSON(h.StatusInternalServerError, http.Response(err, nil))
return
}
c.JSON(h.StatusOK, http.Response(nil, user))
},
)
return nil
}