mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
use *Route to bind json route creation
This commit is contained in:
@@ -12,37 +12,37 @@ func handleRouteCreate(c *gin.Context) {
|
|||||||
store := c.MustGet("store").(models.Datastore)
|
store := c.MustGet("store").(models.Datastore)
|
||||||
log := c.MustGet("log").(logrus.FieldLogger)
|
log := c.MustGet("log").(logrus.FieldLogger)
|
||||||
|
|
||||||
wroute := &models.RouteWrapper{}
|
route := &models.Route{}
|
||||||
|
|
||||||
err := c.BindJSON(wroute)
|
err := c.BindJSON(route)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithError(err).Error(models.ErrInvalidJSON)
|
log.WithError(err).Error(models.ErrInvalidJSON)
|
||||||
c.JSON(http.StatusBadRequest, simpleError(models.ErrInvalidJSON))
|
c.JSON(http.StatusBadRequest, simpleError(models.ErrInvalidJSON))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if wroute.Route == nil {
|
if route == nil {
|
||||||
log.WithError(err).Error(models.ErrInvalidJSON)
|
log.WithError(err).Error(models.ErrInvalidJSON)
|
||||||
c.JSON(http.StatusBadRequest, simpleError(models.ErrRoutesMissingNew))
|
c.JSON(http.StatusBadRequest, simpleError(models.ErrRoutesMissingNew))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
wroute.Route.AppName = c.Param("app")
|
route.AppName = c.Param("app")
|
||||||
|
|
||||||
if err := wroute.Validate(); err != nil {
|
if err := route.Validate(); err != nil {
|
||||||
log.Error(err)
|
log.Error(err)
|
||||||
c.JSON(http.StatusInternalServerError, simpleError(err))
|
c.JSON(http.StatusInternalServerError, simpleError(err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
app, err := store.GetApp(wroute.Route.AppName)
|
app, err := store.GetApp(route.AppName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithError(err).Error(models.ErrAppsGet)
|
log.WithError(err).Error(models.ErrAppsGet)
|
||||||
c.JSON(http.StatusInternalServerError, simpleError(models.ErrAppsGet))
|
c.JSON(http.StatusInternalServerError, simpleError(models.ErrAppsGet))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if app == nil {
|
if app == nil {
|
||||||
app, err = store.StoreApp(&models.App{Name: wroute.Route.AppName})
|
app, err = store.StoreApp(&models.App{Name: route.AppName})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithError(err).Error(models.ErrAppsCreate)
|
log.WithError(err).Error(models.ErrAppsCreate)
|
||||||
c.JSON(http.StatusInternalServerError, simpleError(models.ErrAppsCreate))
|
c.JSON(http.StatusInternalServerError, simpleError(models.ErrAppsCreate))
|
||||||
@@ -50,7 +50,7 @@ func handleRouteCreate(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
route, err := store.StoreRoute(wroute.Route)
|
route, err = store.StoreRoute(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))
|
||||||
|
|||||||
Reference in New Issue
Block a user