From 7bb7b380160b541f718fbabd1f1a9b66ac4affdf Mon Sep 17 00:00:00 2001 From: Tom Kralidis Date: Wed, 24 Jul 2024 08:56:50 -0400 Subject: [PATCH] fix pagination for features/records (#1658) (#1754) * fix pagination for features/records (#1658) * remove given tests already existing --- pygeoapi/api/itemtypes.py | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/pygeoapi/api/itemtypes.py b/pygeoapi/api/itemtypes.py index 33cb517..b43d759 100644 --- a/pygeoapi/api/itemtypes.py +++ b/pygeoapi/api/itemtypes.py @@ -531,17 +531,23 @@ def get_collection_items( 'href': f'{uri}?offset={prev}{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': l10n.translate('Items (next)', request.locale), - 'href': next_href - }) + next_link = False + + if content.get('numberMatched', -1) > (limit + offset): + next_link = True + elif len(content['features']) == limit: + next_link = True + + if next_link: + next_ = offset + limit + next_href = f'{uri}?offset={next_}{serialized_query_params}' + content['links'].append( + { + 'type': 'application/geo+json', + 'rel': 'next', + 'title': l10n.translate('Items (next)', request.locale), + 'href': next_href + }) content['links'].append( {