Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ [#214] added expand to digitaal adress serializer #219

Merged
merged 2 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
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
@@ -1,4 +1,4 @@
openapi: 3.0.3

Check warning on line 1 in src/openklant/components/klantinteracties/openapi.yaml

View workflow job for this annotation

GitHub Actions / Run with component klantinteracties

oas3-api-servers
info:
title: klantinteracties
version: 0.0.3
Expand Down Expand Up @@ -1065,6 +1065,21 @@
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 @@
content:
application/json:
schema:
$ref: '#/components/schemas/PaginatedDigitaalAdresList'
$ref: '#/components/schemas/PaginatedExpandDigitaalAdresList'
description: ''
post:
operationId: digitaleadressenCreate
Expand Down Expand Up @@ -1109,6 +1124,21 @@
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 @@
content:
application/json:
schema:
$ref: '#/components/schemas/DigitaalAdres'
$ref: '#/components/schemas/ExpandDigitaalAdres'
description: ''
put:
operationId: digitaleadressenUpdate
Expand Down Expand Up @@ -3221,6 +3251,22 @@
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 @@ -3694,7 +3740,7 @@
type: array
items:
$ref: '#/components/schemas/CategorieRelatie'
PaginatedDigitaalAdresList:

Check warning on line 3743 in src/openklant/components/klantinteracties/openapi.yaml

View workflow job for this annotation

GitHub Actions / Run with component klantinteracties

oas3-unused-components-schema Potentially unused components schema has been detected.
type: object
required:
- count
Expand All @@ -3717,6 +3763,29 @@
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 Expand Up @@ -3786,7 +3855,7 @@
type: array
items:
$ref: '#/components/schemas/InterneTaak'
PaginatedKlantcontactList:

Check warning on line 3858 in src/openklant/components/klantinteracties/openapi.yaml

View workflow job for this annotation

GitHub Actions / Run with component klantinteracties

oas3-unused-components-schema Potentially unused components schema has been detected.
type: object
required:
- count
Expand Down Expand Up @@ -3855,7 +3924,7 @@
type: array
items:
$ref: '#/components/schemas/PartijIdentificator'
PaginatedPartijList:

Check warning on line 3927 in src/openklant/components/klantinteracties/openapi.yaml

View workflow job for this annotation

GitHub Actions / Run with component klantinteracties

oas3-unused-components-schema Potentially unused components schema has been detected.
type: object
required:
- count
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 @@ -18,6 +18,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
Loading