From f71d8c58772effe2bc27ec8e946bc766d8bac8ba Mon Sep 17 00:00:00 2001 From: Anna Shamray Date: Mon, 19 Aug 2024 17:48:59 +0200 Subject: [PATCH 1/2] :bug: [#329] paginate object_history endpoint --- src/objects/api/v2/views.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/objects/api/v2/views.py b/src/objects/api/v2/views.py index 4c7aae33..d2d24ff1 100644 --- a/src/objects/api/v2/views.py +++ b/src/objects/api/v2/views.py @@ -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) From 0078b72de2b6ee3adf495d7d57b10ced34e6268b Mon Sep 17 00:00:00 2001 From: Anna Shamray Date: Tue, 20 Aug 2024 09:46:02 +0200 Subject: [PATCH 2/2] :white_check_mark: [#329] update object_history test --- src/objects/tests/v2/test_object_api.py | 53 ++++++++++++++----------- 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/src/objects/tests/v2/test_object_api.py b/src/objects/tests/v2/test_object_api.py index f4e3abb8..23bf4933 100644 --- a/src/objects/tests/v2/test_object_api.py +++ b/src/objects/tests/v2/test_object_api.py @@ -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 \