Skip to content

Commit

Permalink
profile loading state
Browse files Browse the repository at this point in the history
  • Loading branch information
muratkaanmesum committed Mar 24, 2024
1 parent 514b088 commit 13fe909
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
10 changes: 8 additions & 2 deletions API/Apps/Profile/api/Serializers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.contrib.auth.models import User
from rest_framework import serializers
from ..models import Profile
from ..models import Profile,Stats


class ProfileGetSerializer(serializers.ModelSerializer):
Expand All @@ -26,4 +26,10 @@ class ProfileFriendsSerializer(serializers.ModelSerializer):

class Meta:
model = Profile
fields = ['friends','nickname','user']
fields = ['friends','nickname','user']


class ProfileStatsSerializer(serializers.ModelSerializer):
class Meta:
model = Stats
fields = ['total_games', 'total_wins', 'total_losses', 'points']
2 changes: 1 addition & 1 deletion API/Apps/Profile/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
urlpatterns = [
#path('profile/', ProfileView.as_view(), name='profile'),
path('profile', ProfileDetailView.as_view(), name='profileDetail'),
path('profile/stats/', ProfileStatsView.as_view(), name='profile_stats'),
path('profile/stats', ProfileStatsView.as_view(), name='profile_stats'),
path('profile/history/', ProfileGameHistoryView.as_view(), name='profile_game_history'),
path('profile/friends', ProfileFriendsView.as_view(), name='profile_friends')
]
5 changes: 3 additions & 2 deletions API/Apps/Profile/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from ..models import Profile
from rest_framework.response import Response

from .Serializers import ProfileGetSerializer, ProfilePostSerializer, ProfileFriendsSerializer
from .Serializers import ProfileGetSerializer, ProfilePostSerializer, ProfileFriendsSerializer, ProfileStatsSerializer


class ProfileView(APIView):
Expand Down Expand Up @@ -61,7 +61,8 @@ def get(self, request):
if not profile:
return Response({"error": "Profile not found"}, status=404)
stats = profile.stats
return Response(stats, status=200)
serializer = ProfileStatsSerializer(stats)
return Response(serializer.data, status=200)

def post(self, request,profile_id):
profile = Profile.objects.get(id=profile_id)
Expand Down

0 comments on commit 13fe909

Please sign in to comment.