Skip to content

Commit

Permalink
✨ [#397] Add endpoints to retrieve statustype, resultaattype and info…
Browse files Browse the repository at this point in the history
…rmatieobjecttype

Note: these endpoints are sloooow if there are many resources
  • Loading branch information
SilviaAmAm committed Oct 11, 2024
1 parent 07fa905 commit 8f16d0e
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 1 deletion.
18 changes: 18 additions & 0 deletions backend/src/openarchiefbeheer/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@
)
from openarchiefbeheer.zaken.api.views import (
CacheZakenView,
InformatieobjecttypeChoicesView,
ResultaattypeChoicesView,
SelectielijstklasseChoicesView,
StatustypeChoicesView,
ZaaktypenChoicesView,
)
from openarchiefbeheer.zaken.api.viewsets import ZakenViewSet
Expand Down Expand Up @@ -111,6 +114,21 @@
SelectielijstklasseChoicesView.as_view(),
name="retrieve-selectielijstklasse-choices",
),
path(
"_statustype-choices/",
StatustypeChoicesView.as_view(),
name="retrieve-statustype-choices",
),
path(
"_informatieobjecttype-choices/",
InformatieobjecttypeChoicesView.as_view(),
name="retrieve-informatieobjecttype-choices",
),
path(
"_resultaattype-choices/",
ResultaattypeChoicesView.as_view(),
name="retrieve-resultaattype-choices",
),
path("", include(router.urls)),
]
),
Expand Down
9 changes: 9 additions & 0 deletions backend/src/openarchiefbeheer/zaken/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@ class Meta:
)


class ChoiceSerializer(serializers.Serializer):
label = serializers.CharField(help_text=_("The description field of the choice."))
value = serializers.CharField(help_text=_("The URL of the choice."))
extra = serializers.CharField(
help_text=_("Any extra information about this choice."),
required=False,
)


class ZaaktypeChoiceSerializer(serializers.Serializer):
label = serializers.CharField(help_text=_("The description field of the zaaktype."))
value = serializers.CharField(help_text=_("The URL field of the zaaktype."))
Expand Down
79 changes: 78 additions & 1 deletion backend/src/openarchiefbeheer/zaken/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,14 @@

from ..models import Zaak
from ..tasks import retrieve_and_cache_zaken_from_openzaak
from ..utils import format_zaaktype_choices, retrieve_selectielijstklasse_choices
from ..utils import (
format_zaaktype_choices,
retrieve_paginated_type,
retrieve_selectielijstklasse_choices,
)
from .filtersets import ZaakFilter
from .serializers import (
ChoiceSerializer,
SelectielijstklasseChoicesQueryParamSerializer,
SelectielijstklasseChoicesSerializer,
ZaaktypeChoiceSerializer,
Expand Down Expand Up @@ -108,3 +113,75 @@ def get(self, request, *args, **kwargs):

choices = retrieve_selectielijstklasse_choices(query_params)
return Response(data=choices)


class StatustypeChoicesView(APIView):
permission_classes = [IsAuthenticated]

@extend_schema(
summary=_("Retrieve statustypen choices"),
description=_(
"Retrieve statustypen from Open Zaak and return a "
"value and a label per statustype. The label is the field 'omschrijving'."
),
tags=["private"],
responses={
200: ChoiceSerializer(many=True),
},
)
@method_decorator(cache_page(60 * 15))
def get(self, request, *args, **kwargs):
results = retrieve_paginated_type("statustypen")

serializer = ChoiceSerializer(data=results, many=True)
serializer.is_valid(raise_exception=True)

return Response(serializer.data, status=status.HTTP_200_OK)


class InformatieobjecttypeChoicesView(APIView):
permission_classes = [IsAuthenticated]

@extend_schema(
summary=_("Retrieve informatieobjecttypen choices"),
description=_(
"Retrieve informatieobjecttypen from Open Zaak and return a "
"value and a label per informatieobjecttype. The label is the field 'omschrijving'."
),
tags=["private"],
responses={
200: ChoiceSerializer(many=True),
},
)
@method_decorator(cache_page(60 * 15))
def get(self, request, *args, **kwargs):
results = retrieve_paginated_type("informatieobjecttypen")

serializer = ChoiceSerializer(data=results, many=True)
serializer.is_valid(raise_exception=True)

return Response(serializer.data, status=status.HTTP_200_OK)


class ResultaattypeChoicesView(APIView):
permission_classes = [IsAuthenticated]

@extend_schema(
summary=_("Retrieve resultaattypen choices"),
description=_(
"Retrieve resultaattypen from Open Zaak and return a "
"value and a label per resultaattype. The label is the field 'omschrijving'."
),
tags=["private"],
responses={
200: ChoiceSerializer(many=True),
},
)
@method_decorator(cache_page(60 * 15))
def get(self, request, *args, **kwargs):
results = retrieve_paginated_type("resultaattypen")

serializer = ChoiceSerializer(data=results, many=True)
serializer.is_valid(raise_exception=True)

return Response(serializer.data, status=status.HTTP_200_OK)
20 changes: 20 additions & 0 deletions backend/src/openarchiefbeheer/zaken/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,3 +336,23 @@ def delete_zaak_and_related_objects(zaak: "Zaak", result_store: ResultStore) ->
delete_relation_object(zrc_client, "zaak", zaak.url, result_store)
delete_documents(result_store)
delete_zaak(zaak, zrc_client, result_store)


@lru_cache
def retrieve_paginated_type(resource_path: str) -> list[DropDownChoice]:
def format_choice(item: dict) -> DropDownChoice:
return {"label": item["omschrijving"] or item["url"], "value": item["url"]}

ztc_service = Service.objects.get(api_type=APITypes.ztc)
ztc_client = build_client(ztc_service)

with ztc_client:
response = ztc_client.get(resource_path)
response.raise_for_status()
data_iterator = pagination_helper(ztc_client, response.json())

results = []
for page in data_iterator:
results += [format_choice(result) for result in page["results"]]

return results

0 comments on commit 8f16d0e

Please sign in to comment.