Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
feat: 🚧 add model to marshall response #192
  • Loading branch information
Angeluz-07 committed Jul 21, 2020
commit 1d3f63aa2567ed77aa75a0caf73e0abd0c2f8f41
8 changes: 7 additions & 1 deletion time_tracker_api/time_entries/time_entries_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ def get_all_paginated(self, conditions: dict = None, **kwargs) -> list:
start = conditions.get("start", None)
conditions.pop("start", None)

return self.repository.find_all(
time_entries = self.repository.find_all(
event_ctx,
conditions=conditions,
custom_sql_conditions=custom_query,
Expand All @@ -471,6 +471,12 @@ def get_all_paginated(self, conditions: dict = None, **kwargs) -> list:
offset=start,
)

return {
'records_total': 0,
'records_filtered': 0,
'data': time_entries,
}

def get(self, id):
event_ctx = self.create_event_context("read")

Expand Down
16 changes: 15 additions & 1 deletion time_tracker_api/time_entries/time_entries_namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,20 @@ def get(self):
return time_entries_dao.get_worked_time(conditions)


time_entry_paginated = ns.model(
'TimeEntryPaginated',
{
'records_total': fields.Integer(
title='Records total', description='Total number of entries.',
),
'records_filtered': fields.Integer(
title='Records filtered',
description='Number of entries returned by the endpoint.',
),
'data': fields.List(fields.Nested(time_entry)),
},
)

paginated_attribs_parser = ns.parser()
paginated_attribs_parser.add_argument(
'length',
Expand All @@ -371,7 +385,7 @@ def get(self):
class PaginatedTimeEntry(Resource):
@ns.expect(paginated_attribs_parser)
@ns.doc('list_time_entries_paginated')
@ns.marshal_list_with(time_entry)
@ns.marshal_list_with(time_entry_paginated)
def get(self):
"""List all time entries paginated"""
conditions = paginated_attribs_parser.parse_args()
Expand Down