adding wrapper on apps and routes create response

This commit is contained in:
Pedro Nasser
2016-08-15 23:22:35 -03:00
parent 43ab8da867
commit b57e6656d2
4 changed files with 28 additions and 8 deletions

View File

@@ -14,9 +14,9 @@ func handleAppCreate(c *gin.Context) {
ctx := c.MustGet("ctx").(context.Context) ctx := c.MustGet("ctx").(context.Context)
log := titancommon.Logger(ctx) log := titancommon.Logger(ctx)
wapp := &models.AppWrapper{} var wapp models.AppWrapper
err := c.BindJSON(wapp) err := c.BindJSON(&wapp)
if err != nil { if err != nil {
log.WithError(err).Debug(models.ErrInvalidJSON) log.WithError(err).Debug(models.ErrInvalidJSON)
c.JSON(http.StatusBadRequest, simpleError(models.ErrInvalidJSON)) c.JSON(http.StatusBadRequest, simpleError(models.ErrInvalidJSON))
@@ -42,7 +42,7 @@ func handleAppCreate(c *gin.Context) {
return return
} }
app, err := Api.Datastore.StoreApp(wapp.App) _, err = Api.Datastore.StoreApp(wapp.App)
if err != nil { if err != nil {
log.WithError(err).Errorln(models.ErrAppsCreate) log.WithError(err).Errorln(models.ErrAppsCreate)
c.JSON(http.StatusInternalServerError, simpleError(models.ErrAppsCreate)) c.JSON(http.StatusInternalServerError, simpleError(models.ErrAppsCreate))
@@ -56,5 +56,5 @@ func handleAppCreate(c *gin.Context) {
return return
} }
c.JSON(http.StatusOK, app) c.JSON(http.StatusCreated, appResponse{"App successfully created", wapp})
} }

View File

@@ -15,6 +15,26 @@ import (
titancommon "github.com/iron-io/titan/common" titancommon "github.com/iron-io/titan/common"
) )
type appResponse struct {
Message string
App models.AppWrapper
}
type appsResponse struct {
Message string
Apps models.AppsWrapper
}
type routeResponse struct {
Message string
Route models.RouteWrapper
}
type routesResponse struct {
Message string
Routes models.RoutesWrapper
}
func testRouter() *gin.Engine { func testRouter() *gin.Engine {
r := gin.Default() r := gin.Default()
ctx := context.Background() ctx := context.Background()

View File

@@ -59,12 +59,12 @@ func handleRouteCreate(c *gin.Context) {
} }
} }
route, err := Api.Datastore.StoreRoute(wroute.Route) _, err = Api.Datastore.StoreRoute(wroute.Route)
if err != nil { if err != nil {
log.WithError(err).Error(models.ErrRoutesCreate) log.WithError(err).Error(models.ErrRoutesCreate)
c.JSON(http.StatusInternalServerError, simpleError(models.ErrRoutesCreate)) c.JSON(http.StatusInternalServerError, simpleError(models.ErrRoutesCreate))
return return
} }
c.JSON(http.StatusOK, route) c.JSON(http.StatusCreated, routeResponse{"Route successfully created", wroute})
} }

View File

@@ -38,12 +38,12 @@ func handleRouteUpdate(c *gin.Context) {
return return
} }
route, err := Api.Datastore.StoreRoute(wroute.Route) _, err = Api.Datastore.StoreRoute(wroute.Route)
if err != nil { if err != nil {
log.WithError(err).Debug(models.ErrAppsCreate) log.WithError(err).Debug(models.ErrAppsCreate)
c.JSON(http.StatusInternalServerError, simpleError(models.ErrAppsCreate)) c.JSON(http.StatusInternalServerError, simpleError(models.ErrAppsCreate))
return return
} }
c.JSON(http.StatusOK, route) c.JSON(http.StatusOK, routeResponse{"Route successfully updated", wroute})
} }