Skip to content

Commit

Permalink
Merge branch 'dev' into apis/post-users
Browse files Browse the repository at this point in the history
  • Loading branch information
Esterello2 authored Dec 6, 2023
2 parents 074d813 + 7303ed3 commit c0bfd4c
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 19 deletions.
14 changes: 13 additions & 1 deletion src/chigame/api/serializers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from rest_framework import serializers

from chigame.games.models import Chat, Game, Lobby, Message, Tournament, User
from chigame.games.models import Category, Chat, Game, Lobby, Mechanic, Message, Tournament, User
from chigame.users.models import Group


Expand Down Expand Up @@ -45,6 +45,18 @@ def create(self, validated_data):
return user


class CategorySerializer(serializers.ModelSerializer):
class Meta:
model = Category
fields = "__all__"


class MechanicSerializer(serializers.ModelSerializer):
class Meta:
model = Mechanic
fields = "__all__"


class MessageSerializer(serializers.ModelSerializer):
sender = serializers.EmailField(write_only=True)

Expand Down
55 changes: 37 additions & 18 deletions src/chigame/api/urls.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,45 @@
from django.urls import path
from django.urls import include, path

from . import views

urlpatterns = [
path("games/", views.GameListView.as_view(), name="api-game-list"),
path("games/<int:pk>/", views.GameDetailView.as_view(), name="api-game-detail"),
game_patterns = [
path("", views.GameListView.as_view(), name="api-game-list"),
path("<int:pk>/", views.GameDetailView.as_view(), name="api-game-detail"),
path("<int:pk>/categories/", views.GameCategoriesAPIView.as_view(), name="api-game-categories"),
path("<int:pk>/mechanics/", views.GameMechanicsAPIView.as_view(), name="api-game-mechanics"),
]

lobby_patterns = [
path("", views.LobbyListView.as_view(), name="api-lobby-list"),
path("<int:pk>/", views.LobbyDetailView.as_view(), name="api-lobby-detail"),
]

user_patterns = [
path("", views.UserListView.as_view(), name="api-user-list"),
path("register/", views.UserRegistrationView.as_view(), name="user-registration"),
# LOBBY API URLS
path("lobbies/", views.LobbyListView.as_view(), name="api-lobby-list"),
path("lobbies/<int:pk>/", views.LobbyDetailView.as_view(), name="api-lobby-detail"),
path("users/", views.UserListView.as_view(), name="api-user-list"),
path("<slug:slug>/", views.UserDetailView.as_view(), name="api-user-detail"),
path("<slug:slug>/groups/", views.UserGroupsView.as_view(), name="api-user-groups"),
path("<int:pk>/friends/", views.UserFriendsAPIView.as_view(), name="api-user-friends"),
]

tournament_patterns = [
path("chat/", views.MessageView.as_view(), name="api-chat-list"),
path("chat/feed/", views.MessageFeedView.as_view(), name="api-chat-detail"),
]

group_patterns = [
path("", views.GroupListView.as_view(), name="api-group-list"),
path("<int:pk>/", views.GroupDetailView.as_view(), name="api-group-detail"),
path("<int:pk>/members/", views.GroupMembersView.as_view(), name="api-group-members"),
]

urlpatterns = [
path("token/", views.CustomTokenObtainPairView.as_view(), name="token_obtain_pair"),
path("token/refresh/", views.CustomTokenRefreshView.as_view(), name="token_refresh"),
path("token/verify/", views.CustomTokenVerifyView.as_view(), name="token_verify"),
path("users/<slug:slug>/", views.UserDetailView.as_view(), name="api-user-detail"),
path("users/<int:pk>/friends/", views.UserFriendsAPIView.as_view(), name="api-user-friends"),
path("users/<slug:slug>/groups/", views.UserGroupsView.as_view(), name="api-user-groups"),
# CHAT API URLS
path("tournaments/chat/", views.MessageView.as_view(), name="api-chat-list"),
path("tournaments/chat/feed/", views.MessageFeedView.as_view(), name="api-chat-detail"),
# GROUP API URLS
path("groups/", views.GroupListView.as_view(), name="api-group-list"),
path("groups/<int:pk>/", views.GroupDetailView.as_view(), name="api-group-detail"),
path("groups/<int:pk>/members/", views.GroupMembersView.as_view(), name="api-group-members"),
path("games/", include(game_patterns)),
path("lobbies/", include(lobby_patterns)),
path("users/", include(user_patterns)),
path("tournaments/", include(tournament_patterns)),
path("groups/", include(group_patterns)),
]
24 changes: 24 additions & 0 deletions src/chigame/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@

from chigame.api.filters import GameFilter
from chigame.api.serializers import (
CategorySerializer,
GameSerializer,
GroupSerializer,
LobbySerializer,
MechanicSerializer,
MessageFeedSerializer,
MessageSerializer,
UserSerializer,
Expand Down Expand Up @@ -48,6 +50,7 @@ class GameDetailView(generics.RetrieveUpdateDestroyAPIView):
serializer_class = GameSerializer



class UserListView(generics.ListAPIView):
queryset = User.objects.all()
serializer_class = UserSerializer
Expand All @@ -70,6 +73,27 @@ def post(self, request, *args, **kwargs):
return Response({"access_token": access_token}, status=status.HTTP_201_CREATED)
return Response(serializer_instance.errors, status=status.HTTP_400_BAD_REQUEST)


class GameCategoriesAPIView(generics.ListAPIView):
serializer_class = CategorySerializer
pagination_class = PageNumberPagination

def get_queryset(self):
game_id = self.kwargs["pk"]
game = Game.objects.get(id=game_id)
return game.categories.all()


class GameMechanicsAPIView(generics.ListAPIView):
serializer_class = MechanicSerializer
pagination_class = PageNumberPagination

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
Expand Down

0 comments on commit c0bfd4c

Please sign in to comment.