Skip to content

Commit

Permalink
Merge pull request #435 from maykinmedia/issue/329-history-paginated
Browse files Browse the repository at this point in the history
🐛 [#329] paginate object_history endpoint
  • Loading branch information
annashamray authored Aug 21, 2024
2 parents 41b8731 + 0078b72 commit 2bf6063
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 24 deletions.
6 changes: 6 additions & 0 deletions src/objects/api/v2/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ def perform_destroy(self, instance):
def history(self, request, uuid=None):
"""Retrieve all RECORDs of an OBJECT."""
records = self.get_object().object.records.order_by("id")

page = self.paginate_queryset(records)
if page is not None:
serializer = self.get_serializer(page, many=True)
return self.get_paginated_response(serializer.data)

serializer = self.get_serializer(records, many=True)
return Response(serializer.data)

Expand Down
53 changes: 29 additions & 24 deletions src/objects/tests/v2/test_object_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,30 +301,35 @@ def test_history_object(self, m):

self.assertEqual(
data,
[
{
"index": 1,
"typeVersion": record1.version,
"data": record1.data,
"geometry": json.loads(record1.geometry.json),
"startAt": record1.start_at.isoformat(),
"endAt": record2.start_at.isoformat(),
"registrationAt": record1.registration_at.isoformat(),
"correctionFor": None,
"correctedBy": 2,
},
{
"index": 2,
"typeVersion": record2.version,
"data": record2.data,
"geometry": json.loads(record2.geometry.json),
"startAt": record2.start_at.isoformat(),
"endAt": None,
"registrationAt": date.today().isoformat(),
"correctionFor": 1,
"correctedBy": None,
},
],
{
"count": 2,
"next": None,
"previous": None,
"results": [
{
"index": 1,
"typeVersion": record1.version,
"data": record1.data,
"geometry": json.loads(record1.geometry.json),
"startAt": record1.start_at.isoformat(),
"endAt": record2.start_at.isoformat(),
"registrationAt": record1.registration_at.isoformat(),
"correctionFor": None,
"correctedBy": 2,
},
{
"index": 2,
"typeVersion": record2.version,
"data": record2.data,
"geometry": json.loads(record2.geometry.json),
"startAt": record2.start_at.isoformat(),
"endAt": None,
"registrationAt": date.today().isoformat(),
"correctionFor": 1,
"correctedBy": None,
},
],
},
)

# In the ticket https://github.com/maykinmedia/objects-api/issues/282 we discovered that updating an object \
Expand Down

0 comments on commit 2bf6063

Please sign in to comment.