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

Method handleAppDelete

api/server/apps_delete.go:13–53  ·  view source on GitHub ↗
(c *gin.Context)

Source from the content-addressed store, hash-verified

11)
12
13func (s *Server) handleAppDelete(c *gin.Context) {
14 ctx := c.MustGet("ctx").(context.Context)
15 log := common.Logger(ctx)
16
17 app := &models.App{Name: c.MustGet(api.AppName).(string)}
18
19 routes, err := s.Datastore.GetRoutesByApp(ctx, app.Name, &models.RouteFilter{})
20 if err != nil {
21 log.WithError(err).Error(models.ErrAppsRemoving)
22 c.JSON(http.StatusInternalServerError, simpleError(ErrInternalServerError))
23 return
24 }
25 //TODO allow this? #528
26 if len(routes) > 0 {
27 log.WithError(err).Debug(models.ErrDeleteAppsWithRoutes)
28 c.JSON(http.StatusBadRequest, simpleError(models.ErrDeleteAppsWithRoutes))
29 return
30 }
31
32 err = s.FireBeforeAppDelete(ctx, app)
33 if err != nil {
34 log.WithError(err).Error(models.ErrAppsRemoving)
35 c.JSON(http.StatusInternalServerError, simpleError(ErrInternalServerError))
36 return
37 }
38
39 err = s.Datastore.RemoveApp(ctx, app.Name)
40 if err != nil {
41 handleErrorResponse(c, err)
42 return
43 }
44
45 err = s.FireAfterAppDelete(ctx, app)
46 if err != nil {
47 log.WithError(err).Error(models.ErrAppsRemoving)
48 c.JSON(http.StatusInternalServerError, simpleError(ErrInternalServerError))
49 return
50 }
51
52 c.JSON(http.StatusOK, gin.H{"message": "App deleted"})
53}

Callers

nothing calls this directly

Calls 8

FireBeforeAppDeleteMethod · 0.95
FireAfterAppDeleteMethod · 0.95
simpleErrorFunction · 0.85
handleErrorResponseFunction · 0.85
LoggerMethod · 0.80
GetRoutesByAppMethod · 0.65
RemoveAppMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected