added config to apps and routes

This commit is contained in:
Pedro Nasser
2016-08-26 23:04:57 -03:00
parent 609d767c3f
commit 2782a6db54
13 changed files with 108 additions and 65 deletions

View File

@@ -56,5 +56,5 @@ func handleAppCreate(c *gin.Context) {
return
}
c.JSON(http.StatusCreated, appResponse{"App successfully created", wapp})
c.JSON(http.StatusCreated, appResponse{"App successfully created", wapp})
}

View File

@@ -11,7 +11,7 @@ import (
)
func TestAppCreate(t *testing.T) {
New(&models.Config{}, &datastore.Mock{}, testRunner(t))
New(&datastore.Mock{}, testRunner(t))
router := testRouter()
for i, test := range []struct {
@@ -52,7 +52,7 @@ func TestAppCreate(t *testing.T) {
}
func TestAppDelete(t *testing.T) {
New(&models.Config{}, &datastore.Mock{}, testRunner(t))
New(&datastore.Mock{}, testRunner(t))
router := testRouter()
for i, test := range []struct {
@@ -83,7 +83,7 @@ func TestAppDelete(t *testing.T) {
}
func TestAppList(t *testing.T) {
New(&models.Config{}, &datastore.Mock{}, testRunner(t))
New(&datastore.Mock{}, testRunner(t))
router := testRouter()
for i, test := range []struct {
@@ -113,7 +113,7 @@ func TestAppList(t *testing.T) {
}
func TestAppGet(t *testing.T) {
New(&models.Config{}, &datastore.Mock{}, testRunner(t))
New(&datastore.Mock{}, testRunner(t))
router := testRouter()
for i, test := range []struct {
@@ -143,7 +143,7 @@ func TestAppGet(t *testing.T) {
}
func TestAppUpdate(t *testing.T) {
New(&models.Config{}, &datastore.Mock{}, testRunner(t))
New(&datastore.Mock{}, testRunner(t))
router := testRouter()
for i, test := range []struct {

View File

@@ -14,34 +14,30 @@ func handleAppUpdate(c *gin.Context) {
ctx := c.MustGet("ctx").(context.Context)
log := titancommon.Logger(ctx)
app := &models.App{}
wapp := models.AppWrapper{}
err := c.BindJSON(app)
err := c.BindJSON(&wapp)
if err != nil {
log.WithError(err).Debug(models.ErrInvalidJSON)
c.JSON(http.StatusBadRequest, simpleError(models.ErrInvalidJSON))
return
}
if app == nil {
if wapp.App == nil {
log.Debug(models.ErrAppsMissingNew)
c.JSON(http.StatusBadRequest, simpleError(models.ErrAppsMissingNew))
return
}
if err := app.Validate(); err != nil {
log.Error(err)
c.JSON(http.StatusInternalServerError, simpleError(err))
app, err := Api.Datastore.StoreApp(wapp.App)
if err != nil {
log.WithError(err).Debug(models.ErrAppsCreate)
c.JSON(http.StatusInternalServerError, simpleError(models.ErrAppsCreate))
return
}
// app, err := Api.Datastore.StoreApp(wapp.App)
// if err != nil {
// log.WithError(err).Debug(models.ErrAppsCreate)
// c.JSON(http.StatusInternalServerError, simpleError(models.ErrAppsCreate))
// return
// }
wapp.App = app
// Nothing to update right now in apps
c.JSON(http.StatusOK, simpleError(models.ErrAppsNothingToUpdate))
c.JSON(http.StatusOK, appResponse{"App successfully updated", wapp})
}

View File

@@ -15,8 +15,8 @@ func handleRouteDelete(c *gin.Context) {
log := titancommon.Logger(ctx)
appName := c.Param("app")
routeName := c.Param("route")
err := Api.Datastore.RemoveRoute(appName, routeName)
routePath := c.Param("route")
err := Api.Datastore.RemoveRoute(appName, routePath)
if err != nil {
log.WithError(err).Debug(models.ErrRoutesRemoving)

View File

@@ -16,9 +16,9 @@ func handleRouteGet(c *gin.Context) {
log := titancommon.Logger(ctx)
appName := c.Param("app")
routeName := c.Param("route")
routePath := c.Param("route")
route, err := Api.Datastore.GetRoute(appName, routeName)
route, err := Api.Datastore.GetRoute(appName, routePath)
if err != nil {
log.WithError(err).Error(models.ErrRoutesGet)
c.JSON(http.StatusInternalServerError, simpleError(models.ErrRoutesGet))