(c *gin.Context)
| 11 | ) |
| 12 | |
| 13 | func (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 | } |
nothing calls this directly
no test coverage detected