Skip to content

Commit

Permalink
✨ [maykinmedia/archiefbeheercomponent#340] Add endpoint to retrieve z…
Browse files Browse the repository at this point in the history
…aken
  • Loading branch information
SilviaAmAm committed May 2, 2024
1 parent b29d0ba commit 65d4903
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 0 deletions.
6 changes: 6 additions & 0 deletions backend/src/openarchiefbeheer/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

app_name = "api"


urlpatterns = [
# API documentation
path(
Expand Down Expand Up @@ -37,5 +38,10 @@
"openarchiefbeheer.api.authentication.urls", namespace="authentication"
),
),
# Actual endpoints
path(
"v1/zaken/",
include("openarchiefbeheer.api.zaken.urls", namespace="zaken"),
),
path("v1/reviewers/", ReviewersView.as_view(), name="reviewers"),
]
Empty file.
9 changes: 9 additions & 0 deletions backend/src/openarchiefbeheer/api/zaken/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from django.urls import path

from .views import ZakenView

app_name = "zaken"

urlpatterns = [
path("", ZakenView.as_view(), name="zaken"),
]
49 changes: 49 additions & 0 deletions backend/src/openarchiefbeheer/api/zaken/views.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 65d4903

Please sign in to comment.