Skip to content

Commit

Permalink
feat: 프로필 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
dkfla committed Aug 8, 2024
1 parent 787a3a3 commit fc2169f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
3 changes: 2 additions & 1 deletion accounts/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,12 @@ def validate(self, data):


class ProfileSerializer(serializers.ModelSerializer):
friend_count = serializers.SerializerMethodField()
friend_count = serializers.SerializerMethodField(read_only=True)

class Meta:
model = User
fields = ["name", "reliability", "profile_img", "friend_count"]
read_only_fields = ["reliability", "friend_count"]

def get_friend_count(self, obj):
return Friend.objects.filter(user=obj).count()
9 changes: 8 additions & 1 deletion accounts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def post(self, request):
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)


@api_view(["GET"])
@api_view(["GET", "PATCH"])
# @authentication_classes([TokenAuthentication])
# @permission_classes([IsAuthenticated])
def profile(request):
Expand All @@ -46,6 +46,13 @@ def profile(request):
serializer = ProfileSerializer(user)
return Response(serializer.data)

elif request.method == "PATCH":
serializer = ProfileSerializer(user, data=request.data, partial=True)
if serializer.is_valid():
serializer.save()
return Response(serializer.data)
return Response({"error": "Invalid data"}, status=status.HTTP_400_BAD_REQUEST)

return Response(
{"error": "Unsupported method"}, status=status.HTTP_405_METHOD_NOT_ALLOWED
)

0 comments on commit fc2169f

Please sign in to comment.