Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added simplified param for cases with less details #1212

Merged
merged 2 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions app/apps/addresses/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
27 changes: 26 additions & 1 deletion app/apps/cases/serializers/case.py
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions app/apps/cases/views/case.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
CaseDocumentSerializer,
CaseDocumentUploadSerializer,
CaseSerializer,
CaseSimplifiedSerializer,
CitizenReportSerializer,
DocumentTypeSerializer,
SubjectSerializer,
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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"):
Expand Down
Loading