Skip to content

Commit

Permalink
Merge pull request #40 from Nuno-Jesus/fixes
Browse files Browse the repository at this point in the history
Fixes
  • Loading branch information
Nuno-Jesus authored Oct 3, 2024
2 parents c5fbdd3 + 8c09859 commit 332cc79
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 24 deletions.
2 changes: 1 addition & 1 deletion backend/pong/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 5.1.1 on 2024-10-03 17:21
# Generated by Django 5.1.1 on 2024-10-03 17:50

import django.db.models.deletion
from django.conf import settings
Expand Down
1 change: 1 addition & 0 deletions backend/pong/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class Meta:
fields = ['id', 'type', 'status', 'description', 'user_id', 'other_user_id', 'created_at']

class GamesSerializer(serializers.ModelSerializer):

class Meta:
model = Games
fields = '__all__'
Expand Down
42 changes: 26 additions & 16 deletions backend/pong/templates/pages/view_profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -310,29 +310,39 @@ <h6 class="graph-value">Quickest Game: {{ stats.quickest_game }}</h6>
</div>
<div class="opponent">
{% if user_view == game.user2_id %}
<a hx-get="{% url 'user-profile' game.user1_id.id %}"
{% if game.user1_id != NULL %}
<a hx-get="{% url 'user-profile' game.user1_id.id %}"
hx-trigger="click"
hx-target="#main"
hx-push-url="true">
{% if "http" in game.user1_id.picture.url %}
<img class="profile-pic" src="{{ game.user1_id.picture }}" alt="Profile">
{% else %}
<img class="profile-pic" src="{{ game.user1_id.picture.url }}" alt="Profile">
{% endif %}
<span class="score">{{ game.user1_id.username }}</span>
</a>
{% else %}
<img class="profile-pic" src="{% static 'assets/icons/profile.png' %}" alt="Profile">
<span class="score">Anonymous</span>
{% endif %}
{% else %}
{% if game.user2_id != NULL %}
<a hx-get="{% url 'user-profile' game.user2_id.id %}"
hx-trigger="click"
hx-target="#main"
hx-push-url="true">
{% if "http" in game.user1_id.picture.url %}
<img class="profile-pic" src="{{ game.user1_id.picture }}" alt="Profile">
{% if "http" in game.user2_id.picture.url %}
<img class="profile-pic" src="{{ game.user2_id.picture }}" alt="Profile">
{% else %}
<img class="profile-pic" src="{{ game.user1_id.picture.url }}" alt="Profile">
<img class="profile-pic" src="{{ game.user2_id.picture.url }}" alt="Profile">
{% endif %}
<span class="score">{{ game.user1_id.username }}</span>
</a>
{% else %}
<a hx-get="{% url 'user-profile' game.user2_id.id %}"
hx-trigger="click"
hx-target="#main"
hx-push-url="true">
{% if "http" in game.user2_id.picture.url %}
<img class="profile-pic" src="{{ game.user2_id.picture }}" alt="Profile">
<span class="score">{{ game.user2_id.username }}</span>
</a>
{% else %}
<img class="profile-pic" src="{{ game.user2_id.picture.url }}" alt="Profile">
<img class="profile-pic" src="{% static 'assets/icons/profile.png' %}" alt="Profile">
<span class="score">Anonymous</span>
{% endif %}
<span class="score">{{ game.user2_id.username }}</span>
</a>
{% endif %}
</div>
</div>
Expand Down
25 changes: 18 additions & 7 deletions backend/pong/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -582,11 +582,7 @@ def game_update(request, game_id):
game.winner_id = player2
game.save()

player1.status = "Online"
player1.save()
player2.status = "Online"
player2.save()


user_stats_update(player1.id, game_id, data)
user_stats_update(player2.id, game_id, data)
game_stats_create(game_id, data)
Expand Down Expand Up @@ -623,13 +619,22 @@ def tournament_create(request):
return JsonResponse({'message': f'Missing key: {str(e)}', 'data': {}}, status=400)

name = data.get('name', '')
nickname = data.get('alias', '')

if name == '':
return JsonResponse({'message': 'The name is blank', 'data': {}}, status=400)
if nickname == '':
return JsonResponse({'message': 'The nickname is blank', 'data': {}}, status=400)

if len(name) > 64:
return JsonResponse({'message': 'The name of the tournament is too long.', 'data': {}}, status=400)

if len(nickname) > 64:
return JsonResponse({'message': 'The nickname is too long.', 'data': {}}, status=400)

tour_serializer = TournamentsSerializer(data=data)
if not tour_serializer.is_valid():
return JsonResponse(tour_serializer.errors, status=400)
return JsonResponse({'message': 'Error in the serializer.', 'tour errors': tour_serializer.errors, 'data': {}}, status=400)

tournament = tour_serializer.save()
user_data = {
Expand All @@ -640,7 +645,7 @@ def tournament_create(request):

tour_user_serializer = TournamentsUsersSerializer(data=user_data)
if not tour_user_serializer.is_valid():
return JsonResponse(tour_user_serializer.errors, status=400)
return JsonResponse({'message': 'Error in the serializer.', 'tour errors': tour_user_serializer.errors, 'data': {}}, status=400)
tour_user_serializer.save()
ic(data['host_id'])
user= Users.objects.get(pk=data['host_id'])
Expand Down Expand Up @@ -692,6 +697,12 @@ def tournament_join(request, tournament_id, user_id):

data['tournament_id'] = tournament_id
data['user_id'] = user_id
nickname = data.get('alias', '')
ic(nickname)
if nickname == '':
return JsonResponse({'message': 'The nickname is blank', 'data': {}}, status=400)
if len(nickname) > 64:
return JsonResponse({'message': 'The nickname is too long.', 'data': {}}, status=400)

serializer = TournamentsUsersSerializer(data=data)
if not serializer.is_valid():
Expand Down

0 comments on commit 332cc79

Please sign in to comment.