mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
Move all endpoints on v1 to be under apps
This commit is contained in:
@@ -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})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user