-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ [maykinmedia/archiefbeheercomponent#340] Add endpoints for destruct…
…ion list
- Loading branch information
1 parent
9647ad6
commit 1033fa9
Showing
4 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |