Skip to content

Commit 47aa514

Browse files
committed
feat: 🚧 add model to marshall response #192
1 parent 389795d commit 47aa514

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

time_tracker_api/time_entries/time_entries_model.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ def get_all_paginated(self, conditions: dict = None, **kwargs) -> list:
461461
start = conditions.get("start", None)
462462
conditions.pop("start", None)
463463

464-
return self.repository.find_all(
464+
time_entries = self.repository.find_all(
465465
event_ctx,
466466
conditions=conditions,
467467
custom_sql_conditions=custom_query,
@@ -470,6 +470,12 @@ def get_all_paginated(self, conditions: dict = None, **kwargs) -> list:
470470
offset=start,
471471
)
472472

473+
return {
474+
'records_total': 0,
475+
'records_filtered': 0,
476+
'data': time_entries,
477+
}
478+
473479
def get(self, id):
474480
event_ctx = self.create_event_context("read")
475481

time_tracker_api/time_entries/time_entries_namespace.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,20 @@ def get(self):
333333
return time_entries_dao.get_worked_time(conditions)
334334

335335

336+
time_entry_paginated = ns.model(
337+
'TimeEntryPaginated',
338+
{
339+
'records_total': fields.Integer(
340+
title='Records total', description='Total number of entries.',
341+
),
342+
'records_filtered': fields.Integer(
343+
title='Records filtered',
344+
description='Number of entries returned by the endpoint.',
345+
),
346+
'data': fields.List(fields.Nested(time_entry)),
347+
},
348+
)
349+
336350
paginated_attribs_parser = ns.parser()
337351
paginated_attribs_parser.add_argument(
338352
'length',
@@ -357,7 +371,7 @@ def get(self):
357371
class PaginatedTimeEntry(Resource):
358372
@ns.expect(paginated_attribs_parser)
359373
@ns.doc('list_time_entries_paginated')
360-
@ns.marshal_list_with(time_entry)
374+
@ns.marshal_list_with(time_entry_paginated)
361375
def get(self):
362376
"""List all time entries paginated"""
363377
conditions = paginated_attribs_parser.parse_args()

0 commit comments

Comments
 (0)