Skip to content

Commit

Permalink
Add total result count to package list API
Browse files Browse the repository at this point in the history
Refs #988

This commit connects the API "GET /package" endpoint to the persistence
layer `ListPackages()` method. The cursor request parameter is replaced
by the optional limit and offset parameters. The response now returns
the current page limit and offset, and the total number of results found
before paging, instead of a cursor value.

These changes will break the existing cursor-based pagination in the
Enduro Dashboard. I will fix the Dashboard paging in a subsequent
commit.

- Add optional `limit` and `offset` parameters to the GET /package
  request
- Add page `limit`, `offset`, and `total` fields to GET /package
  response
- Use `persistence.ListPackages()` to populate API results
- Add an adapter to convert goa `package_.ListPayload` search filters to
  `persistence.Filter` filters
- Add tests for the conversion of the package API parameters to
  persistence layer parameters, and the persistence search results to
  API response results
  • Loading branch information
djjuhasz committed Oct 2, 2024
1 parent 846f026 commit d002e4c
Show file tree
Hide file tree
Showing 26 changed files with 1,119 additions and 288 deletions.
23 changes: 20 additions & 3 deletions internal/api/design/package_.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,12 @@ var _ = Service("package", func() {
Attribute("status", String, func() {
EnumPackageStatus()
})
Attribute("cursor", String, "Pagination cursor")
Attribute("limit", Int, "Limit number of results to return")
Attribute("offset", Int, "Offset from the beginning of the found set")

Token("token", String)
})
Result(PaginatedCollectionOf(StoredPackage))
Result(PackageList)
HTTP(func() {
GET("/")
Response(StatusOK)
Expand All @@ -92,7 +94,8 @@ var _ = Service("package", func() {
Param("latest_created_time")
Param("location_id")
Param("status")
Param("cursor")
Param("limit")
Param("offset")
})
})
})
Expand Down Expand Up @@ -319,6 +322,20 @@ var StoredPackage = ResultType("application/vnd.enduro.stored-package", func() {
Required("id", "status", "created_at")
})

var Page = ResultType("application/vnd.enduro.page", func() {
Description("Page represents a subset of search results.")
Attribute("limit", Int, "Maximum items per page")
Attribute("offset", Int, "Offset from first result to start of page")
Attribute("total", Int, "Total result count before paging")
Required("limit", "offset", "total")
})

var PackageList = ResultType("application/vnd.enduro.packages", func() {
Attribute("items", CollectionOf(StoredPackage))
Attribute("page", Page)
Required("items")
})

var PackageNotFound = Type("PackageNotFound", func() {
Description("Package not found.")
TypeName("PackageNotFound")
Expand Down
4 changes: 3 additions & 1 deletion internal/api/design/pagination.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package design

import "goa.design/goa/v3/dsl"
import (
"goa.design/goa/v3/dsl"
)

func PaginatedCollectionOf(v interface{}, adsl ...func()) interface{} {
return func() {
Expand Down
12 changes: 7 additions & 5 deletions internal/api/gen/http/cli/enduro/cli.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

67 changes: 55 additions & 12 deletions internal/api/gen/http/openapi.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 44 additions & 10 deletions internal/api/gen/http/openapi.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d002e4c

Please sign in to comment.