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

🚧(api) serializer for create route #228

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
20 changes: 20 additions & 0 deletions src/backend/joanie/core/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
19 changes: 19 additions & 0 deletions src/backend/joanie/core/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down