diff --git a/app/apps/addresses/serializers.py b/app/apps/addresses/serializers.py index 137d64c0..ad132d50 100755 --- a/app/apps/addresses/serializers.py +++ b/app/apps/addresses/serializers.py @@ -14,6 +14,16 @@ class MeldingenSerializer(serializers.Serializer): data = serializers.ListField(child=serializers.DictField()) +class RegistrationDetailsSerializer(serializers.Serializer): + registrationNumber = serializers.CharField(required=True) + requester = serializers.DictField() + rentalHouse = serializers.DictField() + requestForOther = serializers.BooleanField() + requestForBedAndBreakfast = serializers.BooleanField() + createdAt = serializers.DateTimeField() + agreementDate = serializers.DateTimeField() + + class PowerbrowserSerializer(serializers.Serializer): baG_ID = serializers.CharField() product = serializers.CharField() diff --git a/app/apps/addresses/views.py b/app/apps/addresses/views.py index 9edece26..826b1c74 100755 --- a/app/apps/addresses/views.py +++ b/app/apps/addresses/views.py @@ -13,6 +13,7 @@ HousingCorporationSerializer, MeldingenSerializer, PowerbrowserSerializer, + RegistrationDetailsSerializer, ) bag_id = OpenApiParameter( @@ -60,6 +61,16 @@ def fetch_meldingen(bag_id, auth_header=None, query_params=None): return response.json(), response.status_code +def fetch_registrations(bag_id, auth_header=None, query_params=None): + url = f"{settings.ZAKEN_API_URL}/addresses/{bag_id}/registrations/" + + response = requests.get( + url, timeout=30, headers=get_headers(auth_header), params=query_params + ) + + return response.json(), response.status_code + + def fetch_residents(bag_id, auth_header=None): url = f"{settings.ZAKEN_API_URL}/addresses/{bag_id}/residents/" @@ -181,6 +192,21 @@ def meldingen_by_bag_id(self, request, bag_id): ) return Response(data, status=status_code) + @extend_schema( + description="Gets all registrations based on bag id.", + responses={status.HTTP_200_OK: RegistrationDetailsSerializer(many=True)}, + ) + @action( + detail=True, + url_path="registrations", + methods=["get"], + ) + def registrations_by_bag_id(self, request, bag_id): + data, status_code = fetch_meldingen( + bag_id, get_keycloak_auth_header_from_request(request), request.query_params + ) + return Response(data, status=status_code) + @action( detail=True, methods=["get"],