Move all endpoints on v1 to be under apps

This commit is contained in:
James
2017-07-26 11:39:35 -07:00
parent 8ade75b868
commit 6ee7619b40
9 changed files with 119 additions and 86 deletions

View File

@@ -3,38 +3,22 @@ package server
import (
"net/http"
"github.com/gin-gonic/gin"
"github.com/fnproject/fn/api"
"github.com/fnproject/fn/api/models"
"github.com/gin-gonic/gin"
)
func (s *Server) handleCallList(c *gin.Context) {
ctx := c.Request.Context()
appName, ok := c.MustGet(api.AppName).(string)
if ok && appName == "" {
name, ok := c.Get(api.AppName)
appName, conv := name.(string)
if ok && conv && appName == "" {
handleErrorResponse(c, models.ErrRoutesValidationMissingAppName)
return
}
_, err := s.Datastore.GetApp(c, appName)
if err != nil {
handleErrorResponse(c, err)
return
}
appRoute, ok := c.MustGet(api.Path).(string)
if ok && appRoute == "" {
handleErrorResponse(c, models.ErrRoutesValidationMissingPath)
return
}
_, err = s.Datastore.GetRoute(c, appName, appRoute)
if err != nil {
handleErrorResponse(c, err)
return
}
filter := models.CallFilter{AppName: appName, Path: appRoute}
filter := models.CallFilter{AppName: appName, Path: c.Query(api.CRoute)}
calls, err := s.Datastore.GetTasks(ctx, &filter)
if err != nil {
@@ -42,5 +26,21 @@ func (s *Server) handleCallList(c *gin.Context) {
return
}
if len(calls) == 0 {
_, err = s.Datastore.GetApp(c, appName)
if err != nil {
handleErrorResponse(c, err)
return
}
if filter.Path != "" {
_, err = s.Datastore.GetRoute(c, appName, filter.Path)
if err != nil {
handleErrorResponse(c, err)
return
}
}
}
c.JSON(http.StatusOK, fnCallsResponse{"Successfully listed calls", calls})
}