mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
* Don't try to delete an app that wasn't successfully created in the case of failure * Allow datastore implementations to inject additional annotations on objects * Allow for datastores transparently adding annotations on apps, fns and triggers. Change NameIn filter to Name for apps. * Move *List types including JSON annotations for App, Fn and Trigger into models * Change return types for GetApps, GetFns and GetTriggers on datastore to be models.*List and ove cursor generation into datastore * Trigger cursor handling fixed into db layer Also changes the name generation so that it is not in the same order as the id (well is random), this means we are now testing our name ordering. * GetFns now respects cursors * Apps now feeds cursor back * Mock fixes * Fixing up api level cursor decoding * Tidy up treatment of cursors in the db layer * Adding conditions for non nil items lists * fix mock test
36 lines
775 B
Go
36 lines
775 B
Go
package server
|
|
|
|
import (
|
|
"encoding/base64"
|
|
"net/http"
|
|
|
|
"github.com/fnproject/fn/api/models"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// TODO: Deprecate with V1 API
|
|
func (s *Server) handleV1AppList(c *gin.Context) {
|
|
ctx := c.Request.Context()
|
|
|
|
filter := &models.AppFilter{}
|
|
filter.Cursor, filter.PerPage = pageParamsV2(c)
|
|
|
|
apps, err := s.datastore.GetApps(ctx, filter)
|
|
if err != nil {
|
|
handleV1ErrorResponse(c, err)
|
|
return
|
|
}
|
|
|
|
var nextCursor string
|
|
if len(apps.Items) > 0 && len(apps.Items) == filter.PerPage {
|
|
last := []byte(apps.Items[len(apps.Items)-1].Name)
|
|
nextCursor = base64.RawURLEncoding.EncodeToString(last)
|
|
}
|
|
|
|
c.JSON(http.StatusOK, appsV1Response{
|
|
Message: "Successfully listed applications",
|
|
NextCursor: nextCursor,
|
|
Apps: apps.Items,
|
|
})
|
|
}
|