Skip to content

Commit e0db5cd

Browse files
authored
Merge pull request #175 from ioet/feat/find-last-time-entry-project#174
Find last time-entry in project closes #175
2 parents 17aa43b + 6aedd9b commit e0db5cd

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

time_tracker_api/time_entries/time_entries_model.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ def find_all(
163163
conditions: dict = {},
164164
custom_sql_conditions: List[str] = [],
165165
date_range: dict = {},
166+
**kwargs,
166167
):
167168
custom_sql_conditions.append(
168169
self.create_sql_date_range_filter(date_range)
@@ -175,6 +176,7 @@ def find_all(
175176
conditions=conditions,
176177
custom_sql_conditions=custom_sql_conditions,
177178
custom_params=custom_params,
179+
max_count=kwargs.get("max_count", None),
178180
)
179181

180182
if time_entries:
@@ -198,6 +200,8 @@ def find_all(
198200

199201
users = AzureConnection().users()
200202
add_user_email_to_time_entries(time_entries, users)
203+
elif not time_entries and len(conditions) > 1:
204+
abort(HTTPStatus.NOT_FOUND, "Time entry not found")
201205
return time_entries
202206

203207
def on_create(self, new_item_data: dict, event_context: EventContext):
@@ -381,11 +385,14 @@ def get_all(self, conditions: dict = None, **kwargs) -> list:
381385
HTTPStatus.FORBIDDEN, "You don't have enough permissions."
382386
)
383387
date_range = self.handle_date_filter_args(args=conditions)
388+
limit = conditions.get("limit", None)
389+
conditions.pop("limit", None)
384390
return self.repository.find_all(
385391
event_ctx,
386392
conditions=conditions,
387393
custom_sql_conditions=custom_query,
388394
date_range=date_range,
395+
max_count=limit,
389396
)
390397

391398
def get(self, id):

time_tracker_api/time_entries/time_entries_namespace.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,16 @@
145145
)
146146

147147
# custom attributes filter
148+
149+
attributes_filter.add_argument(
150+
'limit',
151+
required=False,
152+
type=int,
153+
store_missing=False,
154+
help="(Filter) Amount of data to return",
155+
location='args',
156+
)
157+
148158
attributes_filter.add_argument(
149159
'user_id',
150160
required=False,
@@ -191,6 +201,7 @@ class TimeEntries(Resource):
191201
@ns.doc('list_time_entries')
192202
@ns.expect(attributes_filter)
193203
@ns.marshal_list_with(time_entry)
204+
@ns.response(HTTPStatus.NOT_FOUND, 'Time entry not found')
194205
def get(self):
195206
"""List all time entries"""
196207
conditions = attributes_filter.parse_args()

0 commit comments

Comments
 (0)