MCPcopy
hub / github.com/iron-io/functions / handleAppCreate

Method handleAppCreate

api/server/apps_create.go:12–58  ·  view source on GitHub ↗
(c *gin.Context)

Source from the content-addressed store, hash-verified

10)
11
12func (s *Server) handleAppCreate(c *gin.Context) {
13 ctx := c.MustGet("ctx").(context.Context)
14 log := common.Logger(ctx)
15
16 var wapp models.AppWrapper
17
18 err := c.BindJSON(&wapp)
19 if err != nil {
20 log.WithError(err).Debug(models.ErrInvalidJSON)
21 c.JSON(http.StatusBadRequest, simpleError(models.ErrInvalidJSON))
22 return
23 }
24
25 if wapp.App == nil {
26 log.Debug(models.ErrAppsMissingNew)
27 c.JSON(http.StatusBadRequest, simpleError(models.ErrAppsMissingNew))
28 return
29 }
30
31 if err := wapp.Validate(); err != nil {
32 log.Error(err)
33 c.JSON(http.StatusInternalServerError, simpleError(err))
34 return
35 }
36
37 err = s.FireBeforeAppCreate(ctx, wapp.App)
38 if err != nil {
39 log.WithError(err).Error(models.ErrAppsCreate)
40 c.JSON(http.StatusInternalServerError, simpleError(err))
41 return
42 }
43
44 app, err := s.Datastore.InsertApp(ctx, wapp.App)
45 if err != nil {
46 handleErrorResponse(c, err)
47 return
48 }
49
50 err = s.FireAfterAppCreate(ctx, wapp.App)
51 if err != nil {
52 log.WithError(err).Error(models.ErrAppsCreate)
53 c.JSON(http.StatusInternalServerError, simpleError(err))
54 return
55 }
56
57 c.JSON(http.StatusOK, appResponse{"App successfully created", app})
58}

Callers

nothing calls this directly

Calls 8

ValidateMethod · 0.95
FireBeforeAppCreateMethod · 0.95
FireAfterAppCreateMethod · 0.95
simpleErrorFunction · 0.85
handleErrorResponseFunction · 0.85
LoggerMethod · 0.80
InsertAppMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected