-
Notifications
You must be signed in to change notification settings - Fork 12
/
profile_team.go
48 lines (41 loc) · 1.38 KB
/
profile_team.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
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/security"
"github.com/makeless/makeless-go/struct"
h "net/http"
"strconv"
"sync"
)
func (makeless *Makeless) updateProfileTeam(http makeless_go_http.Http) error {
http.GetRouter().GetEngine().PATCH(
"/api/auth/team/profile",
http.GetAuthenticator().GetMiddleware().MiddlewareFunc(),
http.EmailVerificationMiddleware(makeless.GetConfig().GetConfiguration().GetEmailVerification()),
http.TeamRoleMiddleware(makeless_go_security.RoleTeamOwner),
func(c *gin.Context) {
var err error
var teamId, _ = strconv.Atoi(c.GetHeader("Team"))
var profileTeam = &_struct.ProfileTeam{
RWMutex: new(sync.RWMutex),
}
if err = c.ShouldBind(profileTeam); err != nil {
c.AbortWithStatusJSON(h.StatusBadRequest, http.Response(err, nil))
return
}
var team = &makeless_go_model.Team{
Model: makeless_go_model.Model{Id: uint(teamId)},
Name: profileTeam.GetName(),
RWMutex: new(sync.RWMutex),
}
if team, err = http.GetDatabase().UpdateProfileTeam(http.GetDatabase().GetConnection().WithContext(c), team); err != nil {
c.AbortWithStatusJSON(h.StatusInternalServerError, http.Response(err, nil))
return
}
c.JSON(h.StatusOK, http.Response(nil, team))
},
)
return nil
}