Skip to content

Commit

Permalink
Pagination issue (#1333)
Browse files Browse the repository at this point in the history
* Fix for Django build, changes to documentation, and dev dependencies updated

* remove example configuration files

* Added readthedocs configuration file

* added section on building the documentation

* renamed docs/requirements-docs.txt to docs/requirements.txt

* renamed requirements file in readthedocs configuration

* Added documentation requirements installation to GitHub build workflow

* fixed pagination next page response

* fixed line too long

* Update get_collection_items test to accomodate last page fix

Note that this feature can't be tested with the CSV provider
because it uses the number of current items as numberMatched,
which doesn't seem correct but is an independent issue.
https://github.com/geopython/pygeoapi/blob/c7c07855e5cfa95b88d6d0d11f5c23111e38da95/pygeoapi/provider/csv_.py#L173

---------

Co-authored-by: Juan Pablo Duque <[email protected]>
Co-authored-by: Juan Duque <[email protected]>
  • Loading branch information
3 people authored Aug 16, 2023
1 parent c7c0785 commit 3d93c28
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 20 deletions.
20 changes: 11 additions & 9 deletions pygeoapi/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1709,15 +1709,17 @@ def get_collection_items(
'href': f'{uri}?offset={prev}{serialized_query_params}'
})

if len(content['features']) == limit:
next_ = offset + limit
content['links'].append(
{
'type': 'application/geo+json',
'rel': 'next',
'title': 'items (next)',
'href': f'{uri}?offset={next_}{serialized_query_params}'
})
if 'numberMatched' in content:
if content['numberMatched'] > (limit + offset):
next_ = offset + limit
next_href = f'{uri}?offset={next_}{serialized_query_params}'
content['links'].append(
{
'type': 'application/geo+json',
'rel': 'next',
'title': 'items (next)',
'href': next_href
})

content['links'].append(
{
Expand Down
17 changes: 6 additions & 11 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -907,17 +907,15 @@ def test_get_collection_items(config, api_):
assert features['features'][1]['properties']['stn_id'] == 35

links = features['links']
assert len(links) == 5
assert len(links) == 4
assert '/collections/obs/items?f=json' in links[0]['href']
assert links[0]['rel'] == 'self'
assert '/collections/obs/items?f=jsonld' in links[1]['href']
assert links[1]['rel'] == 'alternate'
assert '/collections/obs/items?f=html' in links[2]['href']
assert links[2]['rel'] == 'alternate'
assert '/collections/obs/items?offset=2&limit=2' in links[3]['href']
assert links[3]['rel'] == 'next'
assert '/collections/obs' in links[4]['href']
assert links[4]['rel'] == 'collection'
assert '/collections/obs' in links[3]['href']
assert links[3]['rel'] == 'collection'

# Invalid offset
req = mock_request({'offset': -1})
Expand Down Expand Up @@ -957,7 +955,7 @@ def test_get_collection_items(config, api_):
assert len(features['features']) == 1

links = features['links']
assert len(links) == 6
assert len(links) == 5
assert '/collections/obs/items?f=json&limit=1&bbox=-180,90,180,90' in \
links[0]['href']
assert links[0]['rel'] == 'self'
Expand All @@ -970,11 +968,8 @@ def test_get_collection_items(config, api_):
assert '/collections/obs/items?offset=0&limit=1&bbox=-180,90,180,90' \
in links[3]['href']
assert links[3]['rel'] == 'prev'
assert '/collections/obs/items?offset=2&limit=1&bbox=-180,90,180,90' \
in links[4]['href']
assert links[4]['rel'] == 'next'
assert '/collections/obs' in links[5]['href']
assert links[5]['rel'] == 'collection'
assert '/collections/obs' in links[4]['href']
assert links[4]['rel'] == 'collection'

req = mock_request({
'sortby': 'bad-property',
Expand Down

0 comments on commit 3d93c28

Please sign in to comment.