Skip to content

Commit

Permalink
Merge pull request #47 from Nihongo-Jouzu/46-feature-endpoint-for-sco…
Browse files Browse the repository at this point in the history
…reboard

Fix: endpoint now giveback the user
  • Loading branch information
FilippoQuattrocchi authored Sep 12, 2024
2 parents 60013f0 + a36e712 commit 117ca91
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
3 changes: 2 additions & 1 deletion backend/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ class Meta:
fields = '__all__'

class ScoreSerializer(serializers.ModelSerializer):
username = serializers.CharField(source="user.username")
class Meta:
model = Score
fields = '__all__'
fields = ['id','score','date','username']

class LobbySerializer(serializers.ModelSerializer):
class Meta:
Expand Down
9 changes: 7 additions & 2 deletions backend/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,16 @@ def user_detail(request, pk):
# Score views
@api_view(["GET"])
def get_scores(request):
scores = Score.objects.all()
limit = request.GET.get('limit')
user_id = request.GET.get('user_id')
if limit is None:
limit = 20
if user_id is None:
user_id = 0
scores = Score.objects.filter(user=user_id).order_by('-date')
serializer = ScoreSerializer(scores, many=True)
return Response(serializer.data)


@api_view(["POST"])
def create_score(request):
serializer = ScoreSerializer(data=request.data)
Expand Down

0 comments on commit 117ca91

Please sign in to comment.