From 475483de9f0e5f9287f23d8e05e1658add549669 Mon Sep 17 00:00:00 2001 From: Justintime50 <39606064+Justintime50@users.noreply.github.com> Date: Mon, 21 Nov 2022 23:24:09 -0700 Subject: [PATCH] feat: adds total_count to collection responses --- CHANGELOG.md | 1 + harvey/api.py | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a23b1b..2aa8d8a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - Bumps `uwsgi` from `2.0.20` to `2.0.21` unlocking Python 3.10 and 3.11 support - Changes from process/threads concurrency to dynamic worker concurrency with uwsgi - Added timeouts and worker kill commands so Harvey will canabolize itself instead of the OS +- Adds `total_count` to collection responses ## v0.20.1 (2022-07-26) diff --git a/harvey/api.py b/harvey/api.py index f35f6d2..f9bfc4a 100644 --- a/harvey/api.py +++ b/harvey/api.py @@ -148,7 +148,7 @@ def retrieve_deployment(deployment_id: str) -> Dict[str, Any]: @staticmethod def retrieve_deployments(request: flask.Request) -> Dict[str, List[Any]]: """Retrieve a list of deployments until the pagination limit is reached.""" - deployments: Dict[str, List[Any]] = {'deployments': []} + deployments: Dict[str, Any] = {'deployments': []} page_size = Api._page_size(request) project_name = request.args.get('project') @@ -166,6 +166,7 @@ def retrieve_deployments(request: flask.Request) -> Dict[str, List[Any]]: pass sorted_deployments = sorted(deployments['deployments'], key=lambda i: i['timestamp'], reverse=True)[:page_size] + deployments['total_count'] = len(deployments['deployments']) deployments['deployments'] = sorted_deployments return deployments @@ -173,7 +174,7 @@ def retrieve_deployments(request: flask.Request) -> Dict[str, List[Any]]: @staticmethod def retrieve_projects(request: flask.Request) -> Dict[str, List[Any]]: """Retrieve a list of projects stored in Harvey by scanning the `projects` directory.""" - projects: Dict[str, List[str]] = {'projects': []} + projects: Dict[str, Any] = {'projects': []} project_owners = os.listdir(Config.projects_path) page_size = Api._page_size(request) @@ -190,11 +191,13 @@ def retrieve_projects(request: flask.Request) -> Dict[str, List[Any]]: if len(projects['projects']) > page_size: break + projects['total_count'] = len(projects['projects']) + return projects @staticmethod def retrieve_locks(request: flask.Request) -> Dict[str, List[Any]]: - locks: Dict[str, List[Any]] = {'locks': []} + locks: Dict[str, Any] = {'locks': []} page_size = Api._page_size(request) @@ -208,6 +211,7 @@ def retrieve_locks(request: flask.Request) -> Dict[str, List[Any]]: ) sorted_locks = sorted(locks['locks'], key=lambda x: x['project'])[:page_size] + locks['total_count'] = len(locks['locks']) locks['locks'] = sorted_locks return locks