Skip to content

Commit

Permalink
Merge pull request #219 from maykinmedia/feature/214-exand-digitaalad…
Browse files Browse the repository at this point in the history
…res-to-betrokkene

✨ [#214] added expand to digitaal adress serializer
  • Loading branch information
bart-maykin authored Aug 15, 2024
2 parents 315786a + 43e7ef7 commit 8a663ff
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ class PartijAdmin(admin.ModelAdmin):
"fields": [
"uuid",
"voorkeurs_digitaal_adres",
"voorkeurs_rekeningnummer",
"nummer",
"interne_notitie",
"soort_partij",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from django_filters.rest_framework import FilterSet

from openklant.components.klantinteracties.api.serializers.digitaal_adres import (
DigitaalAdresSerializer,
)
from openklant.components.utils.filters import ExpandFilter


class DigitaalAdresExpandFilterSet(FilterSet):
expand = ExpandFilter(serializer_class=DigitaalAdresSerializer)
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

from rest_framework import serializers

from openklant.components.klantinteracties.api.serializers.constants import (
SERIALIZER_PATH,
)
from openklant.components.klantinteracties.api.validators import digitaal_adres_exists
from openklant.components.klantinteracties.models.digitaal_adres import DigitaalAdres
from openklant.components.klantinteracties.models.klantcontacten import Betrokkene
Expand Down Expand Up @@ -53,6 +56,16 @@ class DigitaalAdresSerializer(serializers.HyperlinkedModelSerializer):
source="betrokkene",
)

inclusion_serializers = {
# 1 level
"verstrekt_door_betrokkene": f"{SERIALIZER_PATH}.klantcontacten.BetrokkeneSerializer",
# 2 levels
"verstrekt_door_betrokkene.had_klantcontact": f"{SERIALIZER_PATH}.klantcontacten.KlantcontactSerializer",
# 3 levels
"verstrekt_door_betrokkene.had_klantcontact.leidde_tot_interne_taken": f"{SERIALIZER_PATH}"
".internetaken.InterneTaakSerializer",
}

class Meta:
model = DigitaalAdres
fields = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@
from rest_framework import viewsets
from rest_framework.pagination import PageNumberPagination

from openklant.components.klantinteracties.api.filterset.digitaal_adres import (
DigitaalAdresExpandFilterSet,
)
from openklant.components.klantinteracties.api.serializers.digitaal_adres import (
DigitaalAdresSerializer,
)
from openklant.components.klantinteracties.models.digitaal_adres import DigitaalAdres
from openklant.components.token.authentication import TokenAuthentication
from openklant.components.token.permission import TokenPermissions
from openklant.components.utils.mixins import ExpandMixin


@extend_schema(tags=["digitale adressen"])
Expand Down Expand Up @@ -37,7 +41,7 @@
description="Verwijder een digitaal adres.",
),
)
class DigitaalAdresViewSet(viewsets.ModelViewSet):
class DigitaalAdresViewSet(ExpandMixin, viewsets.ModelViewSet):
"""
Digitaal adres dat een betrokkene bij klantcontact verstrekte
voor gebruik bij opvolging van een klantcontact.
Expand All @@ -52,3 +56,10 @@ class DigitaalAdresViewSet(viewsets.ModelViewSet):
pagination_class = PageNumberPagination
authentication_classes = (TokenAuthentication,)
permission_classes = (TokenPermissions,)

@property
def filterset_class(self):
"""
support expand in the detail endpoint
"""
return DigitaalAdresExpandFilterSet
73 changes: 71 additions & 2 deletions src/openklant/components/klantinteracties/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1065,6 +1065,21 @@ paths:
description: Alle digitale adressen opvragen.
summary: Alle digitale adressen opvragen.
parameters:
- in: query
name: expand
schema:
type: array
items:
type: string
enum:
- verstrektDoorBetrokkene
- verstrektDoorBetrokkene.hadKlantcontact
- verstrektDoorBetrokkene.hadKlantcontact.leiddeTotInterneTaken
description: |+
Sluit de gespecifieerde gerelateerde resources in in het antwoord.
explode: false
style: form
- name: page
required: false
in: query
Expand All @@ -1080,7 +1095,7 @@ paths:
content:
application/json:
schema:
$ref: '#/components/schemas/PaginatedDigitaalAdresList'
$ref: '#/components/schemas/PaginatedExpandDigitaalAdresList'
description: ''
post:
operationId: digitaleadressenCreate
Expand Down Expand Up @@ -1109,6 +1124,21 @@ paths:
description: Een specifiek digitaal adres opvragen.
summary: Een specifiek digitaal adres opvragen.
parameters:
- in: query
name: expand
schema:
type: array
items:
type: string
enum:
- verstrektDoorBetrokkene
- verstrektDoorBetrokkene.hadKlantcontact
- verstrektDoorBetrokkene.hadKlantcontact.leiddeTotInterneTaken
description: |+
Sluit de gespecifieerde gerelateerde resources in in het antwoord.
explode: false
style: form
- in: path
name: uuid
schema:
Expand All @@ -1125,7 +1155,7 @@ paths:
content:
application/json:
schema:
$ref: '#/components/schemas/DigitaalAdres'
$ref: '#/components/schemas/ExpandDigitaalAdres'
description: ''
put:
operationId: digitaleadressenUpdate
Expand Down Expand Up @@ -3206,6 +3236,22 @@ components:
required:
- url
- uuid
ExpandDigitaalAdres:
allOf:
- $ref: '#/components/schemas/DigitaalAdres'
- type: object
properties:
_expand:
type: object
description: Display details of the linked resources requested in the
`expand` parameter
properties:
verstrekt_door_betrokkene:
allOf:
- $ref: '#/components/schemas/Betrokkene'
nullable: true
description: Digitaal adres dat een betrokkene bij klantcontact verstrekte
voor gebruik bij opvolging van een klantcontact.
ExpandKlantcontact:
allOf:
- $ref: '#/components/schemas/Klantcontact'
Expand Down Expand Up @@ -3709,6 +3755,29 @@ components:
type: array
items:
$ref: '#/components/schemas/DigitaalAdres'
PaginatedExpandDigitaalAdresList:
type: object
required:
- count
- results
properties:
count:
type: integer
example: 123
next:
type: string
nullable: true
format: uri
example: http://api.example.org/accounts/?page=4
previous:
type: string
nullable: true
format: uri
example: http://api.example.org/accounts/?page=2
results:
type: array
items:
$ref: '#/components/schemas/ExpandDigitaalAdres'
PaginatedExpandKlantcontactList:
type: object
required:
Expand Down
1 change: 1 addition & 0 deletions src/openklant/conf/dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

os.environ.setdefault("RELEASE", "dev")
os.environ.setdefault("LOG_REQUESTS", "no")
os.environ.setdefault("DISABLE_2FA", "yes")

from .base import * # noqa isort:skip

Expand Down

0 comments on commit 8a663ff

Please sign in to comment.