From 8b87b4713bc1a4fbb5c6c618618b03b3a8427ca8 Mon Sep 17 00:00:00 2001 From: Arnav Brahmasandra Date: Sun, 26 Nov 2023 23:15:16 -0600 Subject: [PATCH 01/10] modularized the URLs #294 --- src/chigame/api/urls.py | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/src/chigame/api/urls.py b/src/chigame/api/urls.py index f4145bab..1ed759de 100644 --- a/src/chigame/api/urls.py +++ b/src/chigame/api/urls.py @@ -1,16 +1,30 @@ -from django.urls import path +from django.urls import include, path from . import views +game_patterns = [ + path("", views.GameListView.as_view(), name="api-game-list"), + path("/", views.GameDetailView.as_view(), name="api-game-detail"), + path("/categories/", views.GameCategoriesAPIView.as_view(), name="api-game-categories"), + path("/mechanics/", views.GameMechanicsAPIView.as_view(), name="api-game-mechanics"), +] + +lobby_patterns = [ + path("", views.LobbyListView.as_view(), name="api-lobby-list"), + path("/", views.LobbyDetailView.as_view(), name="api-lobby-detail"), +] + +user_patterns = [ + path("", views.UserListView.as_view(), name="api-user-list"), + path("/", views.UserDetailView.as_view(), name="api-user-detail"), + path("/friends/", views.UserFriendsAPIView.as_view(), name="api-user-friends"), +] + urlpatterns = [ # GAME API URLS - path("games/", views.GameListView.as_view(), name="api-game-list"), - path("games//", views.GameDetailView.as_view(), name="api-game-detail"), + path("games/", include(game_patterns)), # LOBBY API URLS - path("lobbies/", views.LobbyListView.as_view(), name="api-lobby-list"), - path("lobbies//", views.LobbyDetailView.as_view(), name="api-lobby-detail"), + path("lobbies/", include(lobby_patterns)), # USER API URLS - path("users/", views.UserListView.as_view(), name="api-user-list"), - path("users//", views.UserDetailView.as_view(), name="api-user-detail"), - path("users//friends/", views.UserFriendsAPIView.as_view(), name="api-user-friends"), + path("users/", include(user_patterns)), ] From e9b208302b6886c256d20c7587a2d0a37b3cb73a Mon Sep 17 00:00:00 2001 From: Arnav Brahmasandra Date: Sun, 26 Nov 2023 23:17:44 -0600 Subject: [PATCH 02/10] added Category and Mechanic Serializers #294 --- src/chigame/api/serializers.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/chigame/api/serializers.py b/src/chigame/api/serializers.py index aeb069e8..57cd5331 100644 --- a/src/chigame/api/serializers.py +++ b/src/chigame/api/serializers.py @@ -1,6 +1,6 @@ from rest_framework import serializers -from chigame.games.models import Game, Lobby, User +from chigame.games.models import Category, Game, Lobby, Mechanic, User class GameSerializer(serializers.ModelSerializer): @@ -30,3 +30,15 @@ class UserSerializer(serializers.ModelSerializer): class Meta: model = User fields = ("id", "name", "email") + + +class CategorySerializer(serializers.ModelSerializer): + class Meta: + model = Category + fields = "__all__" + + +class MechanicSerializer(serializers.ModelSerializer): + class Meta: + model = Mechanic + fields = "__all__" From c32e921f36709b301a3689fa4de06433ab0b8700 Mon Sep 17 00:00:00 2001 From: Arnav Brahmasandra Date: Sun, 26 Nov 2023 23:18:27 -0600 Subject: [PATCH 03/10] added views to GET game categories and mechanics #294 --- src/chigame/api/views.py | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/chigame/api/views.py b/src/chigame/api/views.py index 5f490d85..76c9a074 100644 --- a/src/chigame/api/views.py +++ b/src/chigame/api/views.py @@ -3,7 +3,13 @@ from rest_framework import generics from chigame.api.filters import GameFilter -from chigame.api.serializers import GameSerializer, LobbySerializer, UserSerializer +from chigame.api.serializers import ( + CategorySerializer, + GameSerializer, + LobbySerializer, + MechanicSerializer, + UserSerializer, +) from chigame.games.models import Game, Lobby, User from chigame.users.models import UserProfile @@ -20,6 +26,24 @@ class GameDetailView(generics.RetrieveUpdateDestroyAPIView): serializer_class = GameSerializer +class GameCategoriesAPIView(generics.RetrieveAPIView): + serializer_class = CategorySerializer + + def get_queryset(self): + game_id = self.kwargs["pk"] + game = Game.objects.get(id=game_id) + return game.categories.all() + + +class GameMechanicsAPIView(generics.RetrieveAPIView): + serializer_class = MechanicSerializer + + def get_queryset(self): + game_id = self.kwargs["pk"] + game = Game.objects.get(id=game_id) + return game.mechanics.all() + + class UserFriendsAPIView(generics.RetrieveAPIView): serializer_class = UserSerializer From 93e2ee882e0daf267dba0e8b957c482531e3f186 Mon Sep 17 00:00:00 2001 From: Arnav Brahmasandra Date: Wed, 29 Nov 2023 10:39:47 -0600 Subject: [PATCH 04/10] fixed typo #295 --- src/chigame/api/views.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/chigame/api/views.py b/src/chigame/api/views.py index dc449c25..bc9c3ff8 100644 --- a/src/chigame/api/views.py +++ b/src/chigame/api/views.py @@ -3,16 +3,15 @@ from rest_framework import generics from chigame.api.filters import GameFilter - from chigame.api.serializers import ( CategorySerializer, GameSerializer, LobbySerializer, MechanicSerializer, - MessageSerializer + MessageSerializer, UserSerializer, ) -from chigame.games.models import Game, Lobby, User, Message +from chigame.games.models import Game, Lobby, Message, User from chigame.users.models import UserProfile From 182c827833edbd56bf164e1f7805ee55e1643c1a Mon Sep 17 00:00:00 2001 From: Arnav Brahmasandra Date: Wed, 29 Nov 2023 10:45:37 -0600 Subject: [PATCH 05/10] linter fixes #295 --- src/chigame/api/serializers.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/chigame/api/serializers.py b/src/chigame/api/serializers.py index 1348b4d6..a76d6c06 100644 --- a/src/chigame/api/serializers.py +++ b/src/chigame/api/serializers.py @@ -1,6 +1,7 @@ from rest_framework import serializers -from chigame.games.models import Chat, Game, Lobby, Message, Tournament, User, Category, Mechanic +from chigame.games.models import Category, Chat, Game, Lobby, Mechanic, Message, Tournament, User + class GameSerializer(serializers.ModelSerializer): class Meta: @@ -42,6 +43,7 @@ class Meta: model = Mechanic fields = "__all__" + class MessageSerializer(serializers.ModelSerializer): sender = serializers.EmailField(write_only=True) From 626f6db87884363db049e15ef1c098cabc4cb4d7 Mon Sep 17 00:00:00 2001 From: Arnav Brahmasandra <107411138+abrahmasandra@users.noreply.github.com> Date: Thu, 30 Nov 2023 18:34:43 +0000 Subject: [PATCH 06/10] removed unnecessary comments #295 --- src/chigame/api/urls.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/chigame/api/urls.py b/src/chigame/api/urls.py index b39bae23..b899ee4c 100644 --- a/src/chigame/api/urls.py +++ b/src/chigame/api/urls.py @@ -21,12 +21,8 @@ ] urlpatterns = [ - # GAME API URLS path("games/", include(game_patterns)), - # LOBBY API URLS path("lobbies/", include(lobby_patterns)), - # USER API URLS path("users/", include(user_patterns)), - # CHAT API URLS path("tournaments/chat/", views.MessageView.as_view(), name="api-chat-list"), ] From a926519d91acd00936e7a29b7c8af25048943555 Mon Sep 17 00:00:00 2001 From: Arnav Brahmasandra <107411138+abrahmasandra@users.noreply.github.com> Date: Tue, 5 Dec 2023 20:59:20 +0000 Subject: [PATCH 07/10] linter --- src/chigame/api/urls.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/chigame/api/urls.py b/src/chigame/api/urls.py index ca7008a3..69bf69cf 100644 --- a/src/chigame/api/urls.py +++ b/src/chigame/api/urls.py @@ -29,5 +29,5 @@ path("games/", include(game_patterns)), path("lobbies/", include(lobby_patterns)), path("users/", include(user_patterns)), - path("tournaments/", include(tournament_patterns)) + path("tournaments/", include(tournament_patterns)), ] From 0cdbd3e01bd9cc31a1e8105736c6210b98fa44a1 Mon Sep 17 00:00:00 2001 From: Arnav Brahmasandra <107411138+abrahmasandra@users.noreply.github.com> Date: Wed, 6 Dec 2023 01:30:50 +0000 Subject: [PATCH 08/10] linter --- src/chigame/api/serializers.py | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/chigame/api/serializers.py b/src/chigame/api/serializers.py index c8569a61..777e32eb 100644 --- a/src/chigame/api/serializers.py +++ b/src/chigame/api/serializers.py @@ -1,15 +1,6 @@ from rest_framework import serializers -from chigame.games.models import ( - Category, - Chat, - Game, - Lobby, - Mechanic, - Message, - Tournament, - User, -) +from chigame.games.models import Category, Chat, Game, Lobby, Mechanic, Message, Tournament, User from chigame.users.models import Group From ee77e2996f6c8d362339ef0fcd3e16166220ba59 Mon Sep 17 00:00:00 2001 From: Arnav Brahmasandra <107411138+abrahmasandra@users.noreply.github.com> Date: Wed, 6 Dec 2023 01:31:45 +0000 Subject: [PATCH 09/10] linter --- src/chigame/api/serializers.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/chigame/api/serializers.py b/src/chigame/api/serializers.py index 777e32eb..b9a344bf 100644 --- a/src/chigame/api/serializers.py +++ b/src/chigame/api/serializers.py @@ -1,7 +1,6 @@ from rest_framework import serializers from chigame.games.models import Category, Chat, Game, Lobby, Mechanic, Message, Tournament, User - from chigame.users.models import Group From 44c84695b6b0023151b7ea96e1ccd9b7e1e995d2 Mon Sep 17 00:00:00 2001 From: Arnav Brahmasandra <107411138+abrahmasandra@users.noreply.github.com> Date: Wed, 6 Dec 2023 01:49:10 +0000 Subject: [PATCH 10/10] fixed issues --- src/chigame/api/views.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/chigame/api/views.py b/src/chigame/api/views.py index fc1e94d5..8d23444b 100644 --- a/src/chigame/api/views.py +++ b/src/chigame/api/views.py @@ -44,8 +44,9 @@ class GameDetailView(generics.RetrieveUpdateDestroyAPIView): serializer_class = GameSerializer -class GameCategoriesAPIView(generics.RetrieveAPIView): +class GameCategoriesAPIView(generics.ListAPIView): serializer_class = CategorySerializer + pagination_class = PageNumberPagination def get_queryset(self): game_id = self.kwargs["pk"] @@ -53,8 +54,9 @@ def get_queryset(self): return game.categories.all() -class GameMechanicsAPIView(generics.RetrieveAPIView): +class GameMechanicsAPIView(generics.ListAPIView): serializer_class = MechanicSerializer + pagination_class = PageNumberPagination def get_queryset(self): game_id = self.kwargs["pk"]