diff --git a/src/backend/joanie/core/api.py b/src/backend/joanie/core/api.py index 74d2cb8de..8ad3ae0ad 100644 --- a/src/backend/joanie/core/api.py +++ b/src/backend/joanie/core/api.py @@ -351,8 +351,28 @@ class AddressViewSet( lookup_field = "id" serializer_class = serializers.AddressSerializer + # serializer_classes = { + # "default": serializers.AddressSerializer, + # "create": serializers.AddressCreateSerializer, + # # ... other actions + # } + action_serializer_classes = { + "create": serializers.AddressCreateSerializer, + "update": serializers.AddressSerializer, + "retrieve": serializers.AddressSerializer, + "list": serializers.AddressSerializer, + "partial_update": serializers.AddressSerializer, + } + permission_classes = [permissions.IsAuthenticated] + def get_serializer_class(self): + try: + return self.action_serializer_classes[self.action] + except (KeyError, AttributeError): + # error_logger.error("---Exception occurred---") + return super(AddressViewSet, self).get_serializer_class() + def get_queryset(self): """Custom queryset to get user addresses""" user = User.update_or_create_from_request_user(request_user=self.request.user) diff --git a/src/backend/joanie/core/serializers.py b/src/backend/joanie/core/serializers.py index 63697dc36..e725e7a3f 100644 --- a/src/backend/joanie/core/serializers.py +++ b/src/backend/joanie/core/serializers.py @@ -534,6 +534,25 @@ class Meta: ] +class AddressCreateSerializer(serializers.ModelSerializer): + """ + Address create model serializer + """ + + class Meta: + model = models.Address + fields = [ + "address", + "city", + "country", + "first_name", + "last_name", + "is_main", + "postcode", + "title", + ] + + class CertificateSerializer(serializers.ModelSerializer): """ Certificate model serializer