Skip to content

Commit

Permalink
fix: small fixes requested by bod (#71)
Browse files Browse the repository at this point in the history
* fix: add missing field to character serializers

* refactor: allow either PATCH or PUT methods when updating character
  • Loading branch information
corp-0 authored Nov 16, 2023
1 parent 3f6cb6c commit 4651f58
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
16 changes: 2 additions & 14 deletions src/persistence/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,15 @@ class CompatibleCharactersRequestSerializer(serializers.Serializer):
class CharacterSerializer(serializers.ModelSerializer):
class Meta:
model = Character
fields = (
"id",
"account",
"fork_compatibility",
"character_sheet_version",
"data",
)
fields = ("id", "account", "fork_compatibility", "character_sheet_version", "data", "last_updated")

read_only_fields = ("id", "last_updated")


class UpdateCharacterSerializer(serializers.ModelSerializer):
class Meta:
model = Character
fields = (
"id",
"account",
"fork_compatibility",
"character_sheet_version",
"data",
)
fields = ("id", "account", "fork_compatibility", "character_sheet_version", "data", "last_updated")

read_only_fields = ("id", "account", "last_updated")

Expand Down
8 changes: 7 additions & 1 deletion src/persistence/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class UpdateCharacterView(GenericAPIView):
serializer_class = UpdateCharacterSerializer
queryset = Character.objects.all()

def patch(self, request, pk):
def update_character(self, request, pk):
try:
character = Character.objects.get(pk=pk)
if character.account != request.user:
Expand All @@ -99,6 +99,12 @@ def patch(self, request, pk):
else:
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

def patch(self, request, pk):
return self.update_character(request, pk)

def put(self, request, pk):
return self.update_character(request, pk)


class DeleteCharacterView(GenericAPIView):
serializer_class = CharacterSerializer
Expand Down

0 comments on commit 4651f58

Please sign in to comment.