forked from bunjlabs/bunjgames
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
646 additions
and
457 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,21 @@ | ||
import time | ||
from rest_framework.generics import ListAPIView | ||
|
||
from django.utils.functional import cached_property | ||
from rest_framework.response import Response | ||
from rest_framework.views import APIView | ||
from common.serializers import GameTypeSerializer | ||
from feud.models import Game as FeudGame | ||
from jeopardy.models import Game as JeopardyGame | ||
from weakest.models import Game as WeakestGame | ||
|
||
from common.serializers import TokenSerializer | ||
|
||
class AvailableGamesListApi(ListAPIView): | ||
serializer_class = GameTypeSerializer | ||
|
||
class TokenContextMixin: | ||
@cached_property | ||
def token(self): | ||
serializer = TokenSerializer(data=self.request.query_params) | ||
serializer.is_valid(raise_exception=True) | ||
return serializer.validated_data.get('token') | ||
|
||
def get_serializer_context(self): | ||
context = dict(token=self.token) | ||
if hasattr(super(), "get_serializer_context"): | ||
context.update(super().get_serializer_context()) | ||
return context | ||
|
||
|
||
class TimeAPI(APIView): | ||
def get(self, request): | ||
return Response(dict( | ||
time=int(round(time.time() * 1000)) | ||
)) | ||
def get_queryset(self): | ||
result = [] | ||
token = self.kwargs['token'] | ||
if FeudGame.objects.filter(token=token).exists(): | ||
result.append(dict(type="feud")) | ||
if JeopardyGame.objects.filter(token=token).exists(): | ||
result.append(dict(type="jeopardy")) | ||
if WeakestGame.objects.filter(token=token).exists(): | ||
result.append(dict(type="weakest")) | ||
return result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
class AvailableGame: | ||
def __init__(self, _type: str, token: str): | ||
self.type = _type | ||
self.token = token |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,5 @@ | ||
from rest_framework import serializers | ||
|
||
|
||
class TokenSerializer(serializers.Serializer): | ||
token = serializers.CharField(allow_null=True, required=False) | ||
|
||
def __init__(self, *args, **kwargs): | ||
serializers.Serializer.__init__(self, *args, **kwargs) | ||
class GameTypeSerializer(serializers.Serializer): | ||
type = serializers.CharField() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters