Skip to content

Commit

Permalink
Merge pull request #236 from maykinmedia/feature/dynamic-pagination
Browse files Browse the repository at this point in the history
Feature/dynamic pagination
  • Loading branch information
annashamray authored Sep 9, 2024
2 parents 7ddde8e + 5f9fdad commit 49a4c12
Show file tree
Hide file tree
Showing 20 changed files with 227 additions and 27 deletions.
2 changes: 1 addition & 1 deletion requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ click-plugins==1.1.1
# via celery
click-repl==0.3.0
# via celery
commonground-api-common==1.13.2
commonground-api-common==1.13.3
# via open-api-framework
coreapi==2.3.3
# via commonground-api-common
Expand Down
2 changes: 1 addition & 1 deletion requirements/ci.txt
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ click-repl==0.3.0
# -c requirements/base.txt
# -r requirements/base.txt
# celery
commonground-api-common==1.13.2
commonground-api-common==1.13.3
# via
# -c requirements/base.txt
# -r requirements/base.txt
Expand Down
2 changes: 1 addition & 1 deletion requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ click-repl==0.3.0
# -c requirements/ci.txt
# -r requirements/ci.txt
# celery
commonground-api-common==1.13.2
commonground-api-common==1.13.3
# via
# -c requirements/ci.txt
# -r requirements/ci.txt
Expand Down
26 changes: 26 additions & 0 deletions src/openklant/components/contactgegevens/api/tests/test_apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,19 @@ def test_update_partial_persoon(self):
)
self.assertEqual(data["land"], "5001")

def test_list_pagination_pagesize_param(self):
list_url = reverse("contactgegevens:persoon-list")
PersoonFactory.create_batch(10)

response = self.client.get(list_url, {"pageSize": 5})

self.assertEqual(response.status_code, status.HTTP_200_OK)

data = response.json()
self.assertEqual(data["count"], 10)
self.assertEqual(len(data["results"]), 5)
self.assertEqual(data["next"], f"http://testserver{list_url}?page=2&pageSize=5")


class OrganisatiesTests(APITestCase):
def test_create_organisatie(self):
Expand Down Expand Up @@ -365,3 +378,16 @@ def test_update_partial_organisatie(self):
},
)
self.assertEqual(data["land"], "5001")

def test_list_pagination_pagesize_param(self):
list_url = reverse("contactgegevens:organisatie-list")
OrganisatieFactory.create_batch(10)

response = self.client.get(list_url, {"pageSize": 5})

self.assertEqual(response.status_code, status.HTTP_200_OK)

data = response.json()
self.assertEqual(data["count"], 10)
self.assertEqual(len(data["results"]), 5)
self.assertEqual(data["next"], f"http://testserver{list_url}?page=2&pageSize=5")
6 changes: 3 additions & 3 deletions src/openklant/components/contactgegevens/api/viewset.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from drf_spectacular.utils import extend_schema, extend_schema_view
from rest_framework import viewsets
from rest_framework.pagination import PageNumberPagination
from vng_api_common.pagination import DynamicPageSizePagination

from openklant.components.contactgegevens.api.serializers import (
OrganisatieSerializer,
Expand Down Expand Up @@ -44,7 +44,7 @@ class OrganisatieViewSet(viewsets.ModelViewSet):
queryset = Organisatie.objects.order_by("-pk")
serializer_class = OrganisatieSerializer
lookup_field = "uuid"
pagination_class = PageNumberPagination
pagination_class = DynamicPageSizePagination
authentication_classes = (TokenAuthentication,)
permission_classes = (TokenPermissions,)

Expand Down Expand Up @@ -82,6 +82,6 @@ class PersoonViewSet(viewsets.ModelViewSet):
queryset = Persoon.objects.order_by("-pk")
serializer_class = PersoonSerializer
lookup_field = "uuid"
pagination_class = PageNumberPagination
pagination_class = DynamicPageSizePagination
authentication_classes = (TokenAuthentication,)
permission_classes = (TokenPermissions,)
12 changes: 12 additions & 0 deletions src/openklant/components/contactgegevens/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ paths:
description: Een pagina binnen de gepagineerde set resultaten.
schema:
type: integer
- name: pageSize
required: false
in: query
description: Het aantal resultaten terug te geven per pagina.
schema:
type: integer
tags:
- organisaties
security:
Expand Down Expand Up @@ -168,6 +174,12 @@ paths:
description: Een pagina binnen de gepagineerde set resultaten.
schema:
type: integer
- name: pageSize
required: false
in: query
description: Het aantal resultaten terug te geven per pagina.
schema:
type: integer
tags:
- personen
security:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,19 @@ def test_list_actor(self):
data = response.json()
self.assertEqual(len(data["results"]), 2)

def test_list_pagination_pagesize_param(self):
list_url = reverse("klantinteracties:actor-list")
ActorFactory.create_batch(10)

response = self.client.get(list_url, {"pageSize": 5})

self.assertEqual(response.status_code, status.HTTP_200_OK)

data = response.json()
self.assertEqual(data["count"], 10)
self.assertEqual(len(data["results"]), 5)
self.assertEqual(data["next"], f"http://testserver{list_url}?page=2&pageSize=5")

def test_read_actor(self):
actor = ActorFactory.create()
detail_url = reverse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,19 @@ def test_list_digitaal_adres(self):
data = response.json()
self.assertEqual(len(data["results"]), 2)

def test_list_pagination_pagesize_param(self):
list_url = reverse("klantinteracties:digitaaladres-list")
DigitaalAdresFactory.create_batch(10)

response = self.client.get(list_url, {"pageSize": 5})

self.assertEqual(response.status_code, status.HTTP_200_OK)

data = response.json()
self.assertEqual(data["count"], 10)
self.assertEqual(len(data["results"]), 5)
self.assertEqual(data["next"], f"http://testserver{list_url}?page=2&pageSize=5")

def test_read_digitaal_adres(self):
digitaal_adres = DigitaalAdresFactory.create()
detail_url = reverse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,19 @@ def test_list_internetaak(self):
data = response.json()
self.assertEqual(len(data["results"]), 2)

def test_list_pagination_pagesize_param(self):
list_url = reverse("klantinteracties:internetaak-list")
InterneTaakFactory.create_batch(10)

response = self.client.get(list_url, {"pageSize": 5})

self.assertEqual(response.status_code, status.HTTP_200_OK)

data = response.json()
self.assertEqual(data["count"], 10)
self.assertEqual(len(data["results"]), 5)
self.assertEqual(data["next"], f"http://testserver{list_url}?page=2&pageSize=5")

def test_read_internetaak(self):
internetaak = InterneTaakFactory.create()
detail_url = reverse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,19 @@ def test_list_klantcontact(self):
self.assertEqual(data["results"][0]["hadBetrokkenActoren"], [])
self.assertEqual(data["results"][1]["hadBetrokkenActoren"], [])

def test_list_pagination_pagesize_param(self):
list_url = reverse("klantinteracties:klantcontact-list")
KlantcontactFactory.create_batch(10)

response = self.client.get(list_url, {"pageSize": 5})

self.assertEqual(response.status_code, status.HTTP_200_OK)

data = response.json()
self.assertEqual(data["count"], 10)
self.assertEqual(len(data["results"]), 5)
self.assertEqual(data["next"], f"http://testserver{list_url}?page=2&pageSize=5")

def test_read_klantcontact(self):
actor = ActorFactory.create(
naam="Phil",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,19 @@ def test_list_partij(self):
],
)

def test_list_pagination_pagesize_param(self):
list_url = reverse("klantinteracties:partij-list")
PartijFactory.create_batch(10)

response = self.client.get(list_url, {"pageSize": 5})

self.assertEqual(response.status_code, status.HTTP_200_OK)

data = response.json()
self.assertEqual(data["count"], 10)
self.assertEqual(len(data["results"]), 5)
self.assertEqual(data["next"], f"http://testserver{list_url}?page=2&pageSize=5")

def test_read_partij(self):
partij = PartijFactory.create()
detail_url = reverse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,19 @@ def test_list_rekeningnummer(self):
data = response.json()
self.assertEqual(len(data["results"]), 2)

def test_list_pagination_pagesize_param(self):
list_url = reverse("klantinteracties:rekeningnummer-list")
RekeningnummerFactory.create_batch(10)

response = self.client.get(list_url, {"pageSize": 5})

self.assertEqual(response.status_code, status.HTTP_200_OK)

data = response.json()
self.assertEqual(data["count"], 10)
self.assertEqual(len(data["results"]), 5)
self.assertEqual(data["next"], f"http://testserver{list_url}?page=2&pageSize=5")

def test_read_rekeningnummer(self):
rekeningnummer = RekeningnummerFactory.create()
detail_url = reverse(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from drf_spectacular.utils import extend_schema, extend_schema_view
from rest_framework import viewsets
from rest_framework.pagination import PageNumberPagination
from vng_api_common.pagination import DynamicPageSizePagination

from openklant.components.klantinteracties.api.filterset.actoren import ActorenFilterSet
from openklant.components.klantinteracties.api.serializers.actoren import (
Expand Down Expand Up @@ -48,7 +48,7 @@ class ActorViewSet(viewsets.ModelViewSet):
)
serializer_class = ActorSerializer
lookup_field = "uuid"
pagination_class = PageNumberPagination
pagination_class = DynamicPageSizePagination
filterset_class = ActorenFilterSet
authentication_classes = (TokenAuthentication,)
permission_classes = (TokenPermissions,)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from drf_spectacular.utils import extend_schema, extend_schema_view
from rest_framework import viewsets
from rest_framework.pagination import PageNumberPagination
from vng_api_common.pagination import DynamicPageSizePagination

from openklant.components.klantinteracties.api.filterset.digitaal_adres import (
DigitaalAdresDetailFilterSet,
Expand Down Expand Up @@ -54,7 +54,7 @@ class DigitaalAdresViewSet(ExpandMixin, viewsets.ModelViewSet):
)
serializer_class = DigitaalAdresSerializer
lookup_field = "uuid"
pagination_class = PageNumberPagination
pagination_class = DynamicPageSizePagination
authentication_classes = (TokenAuthentication,)
permission_classes = (TokenPermissions,)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from drf_spectacular.utils import extend_schema, extend_schema_view
from rest_framework import viewsets
from rest_framework.pagination import PageNumberPagination
from vng_api_common.pagination import DynamicPageSizePagination

from openklant.components.klantinteracties.api.filterset.internetaken import (
InternetaakFilterSet,
Expand Down Expand Up @@ -50,7 +50,7 @@ class InterneTaakViewSet(viewsets.ModelViewSet):
)
serializer_class = InterneTaakSerializer
lookup_field = "uuid"
pagination_class = PageNumberPagination
pagination_class = DynamicPageSizePagination
filterset_class = InternetaakFilterSet
authentication_classes = (TokenAuthentication,)
permission_classes = (TokenPermissions,)
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django_filters.rest_framework import DjangoFilterBackend
from drf_spectacular.utils import extend_schema, extend_schema_view
from rest_framework import viewsets
from rest_framework.pagination import PageNumberPagination
from vng_api_common.pagination import DynamicPageSizePagination

from openklant.components.klantinteracties.api.filterset.klantcontacten import (
ActorKlantcontactFilterSet,
Expand Down Expand Up @@ -68,7 +68,7 @@ class KlantcontactViewSet(ExpandMixin, viewsets.ModelViewSet):
)
serializer_class = KlantcontactSerializer
lookup_field = "uuid"
pagination_class = PageNumberPagination
pagination_class = DynamicPageSizePagination
authentication_classes = (TokenAuthentication,)
permission_classes = (TokenPermissions,)

Expand Down Expand Up @@ -127,7 +127,7 @@ class BetrokkeneViewSet(viewsets.ModelViewSet):
)
serializer_class = BetrokkeneSerializer
lookup_field = "uuid"
pagination_class = PageNumberPagination
pagination_class = DynamicPageSizePagination
filterset_class = BetrokkeneFilterSet
authentication_classes = (TokenAuthentication,)
permission_classes = (TokenPermissions,)
Expand Down Expand Up @@ -167,7 +167,7 @@ class OnderwerpobjectViewSet(viewsets.ModelViewSet):
)
serializer_class = OnderwerpobjectSerializer
lookup_field = "uuid"
pagination_class = PageNumberPagination
pagination_class = DynamicPageSizePagination
filter_backends = [DjangoFilterBackend]
filterset_fields = [
"onderwerpobjectidentificator_object_id",
Expand Down Expand Up @@ -210,7 +210,7 @@ class BijlageViewSet(viewsets.ModelViewSet):
queryset = Bijlage.objects.order_by("-pk").select_related("klantcontact")
serializer_class = BijlageSerializer
lookup_field = "uuid"
pagination_class = PageNumberPagination
pagination_class = DynamicPageSizePagination
filter_backends = [DjangoFilterBackend]
filterset_fields = [
"bijlageidentificator_object_id",
Expand Down Expand Up @@ -258,7 +258,7 @@ class ActorKlantcontactViewSet(viewsets.ModelViewSet):
)
serializer_class = ActorKlantcontactSerializer
lookup_field = "uuid"
pagination_class = PageNumberPagination
pagination_class = DynamicPageSizePagination
filterset_class = ActorKlantcontactFilterSet
authentication_classes = (TokenAuthentication,)
permission_classes = (TokenPermissions,)
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django_filters.rest_framework import DjangoFilterBackend
from drf_spectacular.utils import extend_schema, extend_schema_view
from rest_framework import viewsets
from rest_framework.pagination import PageNumberPagination
from vng_api_common.pagination import DynamicPageSizePagination

from openklant.components.klantinteracties.api.filterset.partijen import (
CategorieRelatieFilterSet,
Expand Down Expand Up @@ -72,7 +72,7 @@ class PartijViewSet(ExpandMixin, viewsets.ModelViewSet):
)
serializer_class = PartijSerializer
lookup_field = "uuid"
pagination_class = PageNumberPagination
pagination_class = DynamicPageSizePagination
authentication_classes = (TokenAuthentication,)
permission_classes = (TokenPermissions,)

Expand Down Expand Up @@ -122,7 +122,7 @@ class VertegenwoordigdenViewSet(viewsets.ModelViewSet):
)
serializer_class = VertegenwoordigdenSerializer
lookup_field = "uuid"
pagination_class = PageNumberPagination
pagination_class = DynamicPageSizePagination
filterset_class = VertegenwoordigdenFilterSet
authentication_classes = (TokenAuthentication,)
permission_classes = (TokenPermissions,)
Expand Down Expand Up @@ -165,7 +165,7 @@ class CategorieRelatieViewSet(viewsets.ModelViewSet):
serializer_class = CategorieRelatieSerializer
lookup_field = "uuid"
filterset_class = CategorieRelatieFilterSet
pagination_class = PageNumberPagination
pagination_class = DynamicPageSizePagination
authentication_classes = (TokenAuthentication,)
permission_classes = (TokenPermissions,)

Expand Down Expand Up @@ -203,7 +203,7 @@ class CategorieViewSet(viewsets.ModelViewSet):
queryset = Categorie.objects.order_by("-pk")
serializer_class = CategorieSerializer
lookup_field = "uuid"
pagination_class = PageNumberPagination
pagination_class = DynamicPageSizePagination
authentication_classes = (TokenAuthentication,)
permission_classes = (TokenPermissions,)

Expand Down Expand Up @@ -241,7 +241,7 @@ class PartijIdentificatorViewSet(viewsets.ModelViewSet):
queryset = PartijIdentificator.objects.order_by("-pk").select_related("partij")
serializer_class = PartijIdentificatorSerializer
lookup_field = "uuid"
pagination_class = PageNumberPagination
pagination_class = DynamicPageSizePagination
filter_backends = [DjangoFilterBackend]
filterset_fields = [
"andere_partij_identificator",
Expand Down
Loading

0 comments on commit 49a4c12

Please sign in to comment.