Skip to content

feat: upper limit = 50 for collections #207

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

Merged
merged 6 commits into from
Oct 2, 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [5.5.1] - 2023-09-21
### Changed
- [#207](https://github.com/unity-sds/unity-data-services/pull/207) feat: upper limit = 50 for collections

## [5.5.0] - 2023-09-28
### Added
- [#201](https://github.com/unity-sds/unity-data-services/pull/201) feat: Custom metadata mechanism
Expand Down
8 changes: 7 additions & 1 deletion cumulus_lambda_functions/uds_api/collections_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,13 @@ async def query_collections(request: Request, collection_id: Union[str, None] =
# NOTE: 2022-11-21: only pass collections. not versions

try:
pagination_links = PaginationLinksGenerator(request).generate_pagination_links()
custom_params = {}
if limit > CollectionDapaQuery.max_limit:
LOGGER.debug(f'incoming limit > {CollectionDapaQuery.max_limit}. resetting to max. incoming limit: {limit}')
limit = CollectionDapaQuery.max_limit
custom_params['limit'] = limit
LOGGER.debug(f'new limit: {limit}')
pagination_links = PaginationLinksGenerator(request, custom_params).generate_pagination_links()
collections_dapa_query = CollectionDapaQuery(collection_id, limit, offset, pagination_links)
collections_result = collections_dapa_query.start()
except Exception as e:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@


class CollectionDapaQuery:
max_limit = 50

def __init__(self, collection_id, limit, offset, pagination_links):
self.__pagination_links = pagination_links
page_number = (offset // limit) + 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@


class PaginationLinksGenerator:
def __init__(self, request: Request):
def __init__(self, request: Request, custom_params: dict = {}):
self.__default_limit = 10
self.__request = request
self.__org_query_params = {k: v for k, v in request.query_params.items()}
self.__org_query_params = {**self.__org_query_params, **custom_params}


def __get_current_page(self):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

setup(
name="cumulus_lambda_functions",
version="5.5.0",
version="5.5.1",
packages=find_packages(),
install_requires=install_requires,
tests_require=['mock', 'nose', 'sphinx', 'sphinx_rtd_theme', 'coverage', 'pystac', 'python-dotenv', 'jsonschema'],
Expand Down
9 changes: 8 additions & 1 deletion tests/cumulus_lambda_functions/uds_api/test_uds_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,19 @@ def test_collections_get(self):
headers = {
'Authorization': f'Bearer {self.bearer_token}',
}
post_url = f'{post_url}?limit=100'
print(post_url)
query_result = requests.get(url=post_url,
headers=headers,
)
self.assertEqual(query_result.status_code, 200, f'wrong status code. {query_result.text}')
print(query_result.text)
query_result = json.loads(query_result.text)
print(query_result)
self.assertTrue('links' in query_result, 'links missing')
links = {k['rel']: k for k in query_result['links']}
self.assertTrue('next' in links, f'missing next in links: {links}')
self.assertTrue('href' in links['next'], f'missing next in links: {links}')
self.assertTrue('limit=50' in links['next']['href'], f"limit not reset to 50: {links['next']['href']}")
return

def test_granules_get(self):
Expand Down