diff --git a/backend/src/openarchiefbeheer/api/urls.py b/backend/src/openarchiefbeheer/api/urls.py index db6bb8dd..e5815372 100644 --- a/backend/src/openarchiefbeheer/api/urls.py +++ b/backend/src/openarchiefbeheer/api/urls.py @@ -35,4 +35,9 @@ "openarchiefbeheer.api.authentication.urls", namespace="authentication" ), ), + # Actual endpoints + path( + "v1/zaken/", + include("openarchiefbeheer.api.zaken.urls", namespace="zaken"), + ), ] diff --git a/backend/src/openarchiefbeheer/api/zaken/__init__.py b/backend/src/openarchiefbeheer/api/zaken/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/backend/src/openarchiefbeheer/api/zaken/urls.py b/backend/src/openarchiefbeheer/api/zaken/urls.py new file mode 100644 index 00000000..4186f797 --- /dev/null +++ b/backend/src/openarchiefbeheer/api/zaken/urls.py @@ -0,0 +1,9 @@ +from django.urls import path + +from .views import ZakenView + +app_name = "zaken" + +urlpatterns = [ + path("", ZakenView.as_view(), name="zaken"), +] diff --git a/backend/src/openarchiefbeheer/api/zaken/views.py b/backend/src/openarchiefbeheer/api/zaken/views.py new file mode 100644 index 00000000..0b29045b --- /dev/null +++ b/backend/src/openarchiefbeheer/api/zaken/views.py @@ -0,0 +1,49 @@ +from django.utils.translation import gettext_lazy as _ + +from drf_spectacular.utils import extend_schema +from requests.exceptions import RequestException +from rest_framework.renderers import JSONRenderer +from rest_framework.request import Request +from rest_framework.response import Response +from rest_framework.views import APIView +from zgw_consumers.client import build_client +from zgw_consumers.constants import APITypes +from zgw_consumers.models import Service + +from openarchiefbeheer.destruction.utils import process_zaken + + +@extend_schema( + summary=_("List zaken"), + description=_( + "Retrieve zaken using the configured ZRC service. " + "Zaken already included in a destruction list are not returned. " + "For information over the query parameters accepted and the schema of the response, look at the " + "'/zaken/api/v1/zaken' list endpoint of Open Zaak." + ), +) +class ZakenView(APIView): + # We don't want the CamelCase renderer to alter the responses from Open Zaak + renderer_classes = (JSONRenderer,) + + def get(self, request: Request) -> Response: + zrc_service = Service.objects.get(api_type=APITypes.zrc) + zrc_client = build_client(zrc_service) + + with zrc_client: + response = zrc_client.get( + "zaken", + headers={"Accept-Crs": "EPSG:4326"}, + params=request.query_params, + ) + + try: + response.raise_for_status() + except RequestException: + return Response({"error": response.json()}, status=response.status_code) + + response_data = response.json() + + response_data["results"] = process_zaken(response_data["results"]) + + return Response(response_data, status=response.status_code)