forked from fnproject/fn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
apps_update.go
53 lines (41 loc) · 968 Bytes
/
apps_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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package server
import (
"net/http"
"github.com/fnproject/fn/api"
"github.com/fnproject/fn/api/models"
"github.com/gin-gonic/gin"
)
func (s *Server) handleAppUpdate(c *gin.Context) {
ctx := c.Request.Context()
wapp := models.AppWrapper{}
err := c.BindJSON(&wapp)
if err != nil {
handleErrorResponse(c, models.ErrInvalidJSON)
return
}
if wapp.App == nil {
handleErrorResponse(c, models.ErrAppsMissingNew)
return
}
if wapp.App.Name != "" {
handleErrorResponse(c, models.ErrAppsNameImmutable)
return
}
wapp.App.Name = c.MustGet(api.AppName).(string)
err = s.FireAfterAppUpdate(ctx, wapp.App)
if err != nil {
handleErrorResponse(c, err)
return
}
app, err := s.Datastore.UpdateApp(ctx, wapp.App)
if err != nil {
handleErrorResponse(c, err)
return
}
err = s.FireAfterAppUpdate(ctx, wapp.App)
if err != nil {
handleErrorResponse(c, err)
return
}
c.JSON(http.StatusOK, appResponse{"App successfully updated", app})
}