Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pagination issue #1333

Merged
merged 14 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading