infratographer / fertilesoil

A general directory tree manager to build apps on
Apache License 2.0
4 stars 3 forks source link

Add pagination #94

Closed mikemrm closed 1 year ago

mikemrm commented 1 year ago

This adds pagination for list responses.

Here is an example of the new output:

$ curl -s 'http://localhost:8080/api/v1/roots?limit=2' | jq '.'
{
  "_links": {
    "next": {
      "href": "http://localhost:8080/api/v1/roots?limit=2&page=2"
    }
  },
  "directories": [
    "de790ebc-205d-47e8-8b2a-f6b263b4e1e1",
    "317046c7-0c62-4cc2-8b27-c639b4aa20ec"
  ],
  "page": 1,
  "page_size": 2,
  "version": "v1"
}

Following the next link results in:

$ curl -s 'http://localhost:8080/api/v1/roots?limit=2&page=2' | jq '.'
{
  "_links": {
    "next": null
  },
  "directories": [
    "459368e6-06b6-49d4-bde8-6049f0399256"
  ],
  "page": 2,
  "page_size": 2,
  "version": "v1"
}

This implementation is pretty simple. So long as response count is equal to the limit, a next page link is provided.

The pros of this method, is it's very simple to implement.

The cons is that it's possible if the last set of results has the same count as the limit, an additional request is necessary which will result in an empty result.

I believe this is an acceptable limitation for now.

This will resolve #32

codecov[bot] commented 1 year ago

Codecov Report

Merging #94 (6ff6a6c) into main (7561e14) will increase coverage by 0.01%. The diff coverage is 92.23%.

@@            Coverage Diff             @@
##             main      #94      +/-   ##
==========================================
+ Coverage   94.04%   94.05%   +0.01%     
==========================================
  Files           7        7              
  Lines        1007     1178     +171     
==========================================
+ Hits          947     1108     +161     
- Misses         46       54       +8     
- Partials       14       16       +2     
Flag Coverage Δ
unittests 94.05% <92.23%> (+0.01%) :arrow_up:

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
internal/httpsrv/treemanager/treemanager.go 92.16% <86.88%> (-0.23%) :arrow_down:
internal/httpsrv/treemanager/config.go 100.00% <100.00%> (ø)
storage/crdb/driver/driver.go 93.59% <100.00%> (+1.04%) :arrow_up:

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.