mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
48 lines
1.1 KiB
Go
48 lines
1.1 KiB
Go
package server
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"gitlab-odx.oracle.com/odx/functions/api"
|
|
"gitlab-odx.oracle.com/odx/functions/api/models"
|
|
)
|
|
|
|
func (s *Server) handleCallList(c *gin.Context) {
|
|
ctx := c.MustGet("ctx").(context.Context)
|
|
|
|
appName, ok := c.MustGet(api.AppName).(string)
|
|
if ok && appName == "" {
|
|
c.JSON(http.StatusBadRequest, models.ErrRoutesValidationMissingAppName)
|
|
return
|
|
}
|
|
|
|
_, err := s.Datastore.GetApp(c, appName)
|
|
if err != nil {
|
|
c.JSON(http.StatusNotFound, models.ErrAppsNotFound)
|
|
return
|
|
}
|
|
|
|
appRoute, ok := c.MustGet(api.Path).(string)
|
|
if ok && appRoute == "" {
|
|
c.JSON(http.StatusBadRequest, models.ErrRoutesValidationMissingPath)
|
|
return
|
|
}
|
|
_, err = s.Datastore.GetRoute(c, appName, appRoute)
|
|
if err != nil {
|
|
c.JSON(http.StatusNotFound, models.ErrRoutesNotFound)
|
|
return
|
|
}
|
|
|
|
filter := models.CallFilter{AppName: appName, Path: appRoute}
|
|
|
|
calls, err := s.Datastore.GetTasks(ctx, &filter)
|
|
if err != nil {
|
|
handleErrorResponse(c, err)
|
|
return
|
|
}
|
|
|
|
c.JSON(http.StatusOK, fnCallsResponse{"Successfully listed calls", calls})
|
|
}
|