Skip to content

Commit

Permalink
WON-51-TOP-BE Added endpoint for fetching registrations by BAG ID
Browse files Browse the repository at this point in the history
  • Loading branch information
remyvdwereld committed Jan 2, 2025
1 parent 11fa3c2 commit fe5ed43
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
10 changes: 10 additions & 0 deletions app/apps/addresses/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
26 changes: 26 additions & 0 deletions app/apps/addresses/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
HousingCorporationSerializer,
MeldingenSerializer,
PowerbrowserSerializer,
RegistrationDetailsSerializer,
)

bag_id = OpenApiParameter(
Expand Down Expand Up @@ -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/"

Expand Down Expand Up @@ -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"],
Expand Down

0 comments on commit fe5ed43

Please sign in to comment.