api: add support for deleting apps (#327)

* api: add support for deleting apps

Fixes #274

* functions: improve error name and description

* functions: fix test regression
This commit is contained in:
C Cirello
2016-11-22 01:07:30 +01:00
committed by GitHub
parent be6685b361
commit da96ef471a
5 changed files with 89 additions and 30 deletions

View File

@@ -14,13 +14,25 @@ func handleAppDelete(c *gin.Context) {
log := common.Logger(ctx)
appName := c.Param("app")
err := Api.Datastore.RemoveApp(appName)
routes, err := Api.Datastore.GetRoutesByApp(appName, &models.RouteFilter{})
if err != nil {
log.WithError(err).Debug(models.ErrAppsRemoving)
c.JSON(http.StatusInternalServerError, simpleError(models.ErrAppsRemoving))
return
}
if len(routes) > 0 {
log.WithError(err).Debug(models.ErrDeleteAppsWithRoutes)
c.JSON(http.StatusBadRequest, simpleError(models.ErrDeleteAppsWithRoutes))
return
}
if err := Api.Datastore.RemoveApp(appName); err != nil {
log.WithError(err).Debug(models.ErrAppsRemoving)
c.JSON(http.StatusInternalServerError, simpleError(models.ErrAppsRemoving))
return
}
c.JSON(http.StatusOK, gin.H{"message": "App deleted"})
}