diff --git a/app/apps/addresses/serializers.py b/app/apps/addresses/serializers.py index 438a985c7..7e878b280 100644 --- a/app/apps/addresses/serializers.py +++ b/app/apps/addresses/serializers.py @@ -82,6 +82,19 @@ class Meta: ) +# AddressSimplifiedSerializer is used for the cases in Zakenoverzicht with just a few details. +class AddressSimplifiedSerializer(serializers.ModelSerializer): + class Meta: + model = Address + fields = ( + "street_name", + "postal_code", + "number", + "suffix_letter", + "suffix", + ) + + class ResidentSerializer(serializers.Serializer): geboortedatum = serializers.DateTimeField(required=True) geslachtsaanduiding = serializers.ChoiceField(choices=("M", "V", "X")) diff --git a/app/apps/cases/serializers/case.py b/app/apps/cases/serializers/case.py index 5a5f23b60..e00846661 100644 --- a/app/apps/cases/serializers/case.py +++ b/app/apps/cases/serializers/case.py @@ -1,5 +1,9 @@ from apps.addresses.models import Address, HousingCorporation -from apps.addresses.serializers import AddressSerializer, AddressTinySerializer +from apps.addresses.serializers import ( + AddressSerializer, + AddressSimplifiedSerializer, + AddressTinySerializer, +) from apps.cases.models import ( Advertisement, Case, @@ -243,6 +247,27 @@ class Meta: ) +# CaseSimplifiedSerializer is used for the cases in Zakenoverzicht with just a few details. +class CaseSimplifiedSerializer(serializers.ModelSerializer): + address = AddressSimplifiedSerializer(read_only=True) + workflows = CaseWorkflowBaseSerializer( + source="get_workflows", many=True, read_only=True + ) + reason = CaseReasonSerializer(read_only=True) + + class Meta: + model = Case + fields = ( + "address", + "end_date", + "id", + "reason", + "workflows", + "start_date", + "last_updated", + ) + + class CaseDocumentSerializer(serializers.ModelSerializer): class Meta: model = CaseDocument diff --git a/app/apps/cases/views/case.py b/app/apps/cases/views/case.py index df4706ad9..628e5352e 100644 --- a/app/apps/cases/views/case.py +++ b/app/apps/cases/views/case.py @@ -20,6 +20,7 @@ CaseDocumentSerializer, CaseDocumentUploadSerializer, CaseSerializer, + CaseSimplifiedSerializer, CitizenReportSerializer, DocumentTypeSerializer, SubjectSerializer, @@ -389,6 +390,7 @@ class StandardResultsSetPagination(EmptyPagination): "schedule_week_segment", OpenApiTypes.NUMBER, OpenApiParameter.QUERY ), OpenApiParameter("sensitive", OpenApiTypes.BOOL, OpenApiParameter.QUERY), + OpenApiParameter("simplified", OpenApiTypes.BOOL, OpenApiParameter.QUERY), OpenApiParameter("start_date", OpenApiTypes.DATE, OpenApiParameter.QUERY), OpenApiParameter("state_types", OpenApiTypes.NUMBER, OpenApiParameter.QUERY), OpenApiParameter("state_types__name", OpenApiTypes.STR, OpenApiParameter.QUERY), @@ -420,6 +422,10 @@ class CaseViewSet( pagination_class = StandardResultsSetPagination def get_serializer_class(self): + # Send `simplified` as parameter to use a simplified serializer with less details. + is_simplified = self.request.query_params.get("simplified", False) == "true" + if is_simplified: + return CaseSimplifiedSerializer if self.action == "retrieve": return CaseDetailSerializer if self.action in ("create", "update", "partial_update"):