From 82b80aafd72718685601ffb7476f70ca3469a5be Mon Sep 17 00:00:00 2001 From: Dickson Armijos Date: Tue, 23 Jun 2020 15:50:32 -0500 Subject: [PATCH 1/3] feat: Add new attribute for the time-entries endpoint --- .../time_entries/time_entries_namespace.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/time_tracker_api/time_entries/time_entries_namespace.py b/time_tracker_api/time_entries/time_entries_namespace.py index 40844fb6..aa1d602c 100644 --- a/time_tracker_api/time_entries/time_entries_namespace.py +++ b/time_tracker_api/time_entries/time_entries_namespace.py @@ -145,6 +145,16 @@ ) # custom attributes filter + +attributes_filter.add_argument( + 'limit', + required=False, + type=int, + store_missing=False, + help="(Filter) Amount of data to return", + location='args', +) + attributes_filter.add_argument( 'user_id', required=False, From 056d0c9867f80aa193ee1c927649c2fa31248f75 Mon Sep 17 00:00:00 2001 From: Dickson Armijos Date: Tue, 23 Jun 2020 15:53:44 -0500 Subject: [PATCH 2/3] feat: Get data by a limit number --- time_tracker_api/time_entries/time_entries_model.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/time_tracker_api/time_entries/time_entries_model.py b/time_tracker_api/time_entries/time_entries_model.py index 98b524cf..4345a2c1 100644 --- a/time_tracker_api/time_entries/time_entries_model.py +++ b/time_tracker_api/time_entries/time_entries_model.py @@ -163,6 +163,7 @@ def find_all( conditions: dict = {}, custom_sql_conditions: List[str] = [], date_range: dict = {}, + **kwargs, ): custom_sql_conditions.append( self.create_sql_date_range_filter(date_range) @@ -175,6 +176,7 @@ def find_all( conditions=conditions, custom_sql_conditions=custom_sql_conditions, custom_params=custom_params, + max_count=kwargs.get("max_count", None), ) if time_entries: @@ -381,11 +383,14 @@ def get_all(self, conditions: dict = None, **kwargs) -> list: HTTPStatus.FORBIDDEN, "You don't have enough permissions." ) date_range = self.handle_date_filter_args(args=conditions) + limit = conditions.get("limit", None) + conditions.pop("limit", None) return self.repository.find_all( event_ctx, conditions=conditions, custom_sql_conditions=custom_query, date_range=date_range, + max_count=limit, ) def get(self, id): From 6aedd9b9cc37b98d5bc2220247e3fa909bade723 Mon Sep 17 00:00:00 2001 From: Dickson Armijos Date: Tue, 23 Jun 2020 16:38:56 -0500 Subject: [PATCH 3/3] feat: 404 error for data not found --- time_tracker_api/time_entries/time_entries_model.py | 2 ++ time_tracker_api/time_entries/time_entries_namespace.py | 1 + 2 files changed, 3 insertions(+) diff --git a/time_tracker_api/time_entries/time_entries_model.py b/time_tracker_api/time_entries/time_entries_model.py index 4345a2c1..5456be70 100644 --- a/time_tracker_api/time_entries/time_entries_model.py +++ b/time_tracker_api/time_entries/time_entries_model.py @@ -200,6 +200,8 @@ def find_all( users = AzureConnection().users() add_user_email_to_time_entries(time_entries, users) + elif not time_entries and len(conditions) > 1: + abort(HTTPStatus.NOT_FOUND, "Time entry not found") return time_entries def on_create(self, new_item_data: dict, event_context: EventContext): diff --git a/time_tracker_api/time_entries/time_entries_namespace.py b/time_tracker_api/time_entries/time_entries_namespace.py index aa1d602c..5a69b938 100644 --- a/time_tracker_api/time_entries/time_entries_namespace.py +++ b/time_tracker_api/time_entries/time_entries_namespace.py @@ -201,6 +201,7 @@ class TimeEntries(Resource): @ns.doc('list_time_entries') @ns.expect(attributes_filter) @ns.marshal_list_with(time_entry) + @ns.response(HTTPStatus.NOT_FOUND, 'Time entry not found') def get(self): """List all time entries""" conditions = attributes_filter.parse_args()