Compare commits
No commits in common. "9714918de915d9196d621de13c120f4201021433" and "acba77e22872e2b99bd07c59b23e09a47afc70ba" have entirely different histories.
9714918de9
...
acba77e228
@ -25,7 +25,6 @@ pip install -r requirements.txt
|
|||||||
python manage.py makemigrations games
|
python manage.py makemigrations games
|
||||||
python manage.py makemigrations profiles
|
python manage.py makemigrations profiles
|
||||||
python manage.py makemigrations chat
|
python manage.py makemigrations chat
|
||||||
python manage.py makemigrations tournament
|
|
||||||
python manage.py migrate
|
python manage.py migrate
|
||||||
```
|
```
|
||||||
- Start the developpement server
|
- Start the developpement server
|
||||||
|
@ -33,7 +33,7 @@ class Account
|
|||||||
|
|
||||||
if (JSON.stringify(response_data) == JSON.stringify({'detail': 'Authentication credentials were not provided.'}))
|
if (JSON.stringify(response_data) == JSON.stringify({'detail': 'Authentication credentials were not provided.'}))
|
||||||
{
|
{
|
||||||
this.client._update_logged(false);
|
this.client._logged = false;
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (response_data == "user deleted")
|
if (response_data == "user deleted")
|
||||||
|
@ -8,7 +8,7 @@ class MatchMaking
|
|||||||
constructor(client)
|
constructor(client)
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @type {Client}
|
* @type {client}
|
||||||
*/
|
*/
|
||||||
this.client = client
|
this.client = client
|
||||||
}
|
}
|
||||||
|
@ -1,19 +0,0 @@
|
|||||||
import { Client } from "./client.js";
|
|
||||||
|
|
||||||
class Tourmanent
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @param {Client} client
|
|
||||||
*/
|
|
||||||
constructor(client)
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @type {Client}
|
|
||||||
*/
|
|
||||||
this.client = client
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
export { Tourmanent }
|
|
@ -1,33 +0,0 @@
|
|||||||
import { Client } from "./client.js";
|
|
||||||
|
|
||||||
class Tourmanents
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @param {Client} client
|
|
||||||
*/
|
|
||||||
constructor(client)
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @type {Client}
|
|
||||||
*/
|
|
||||||
this.client = client
|
|
||||||
}
|
|
||||||
|
|
||||||
async createTournament(nb_players, online)
|
|
||||||
{
|
|
||||||
if (online)
|
|
||||||
return "offline";
|
|
||||||
let response = await this.client._post("/api/tournaments/", {numbers_of_players: nb_players});
|
|
||||||
let response_data = await response.json();
|
|
||||||
|
|
||||||
if (JSON.stringify(response_data) === JSON.stringify({'detail': 'Authentication credentials were not provided.'}))
|
|
||||||
{
|
|
||||||
this.client._update_logged(false);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return response_data.tournament_id;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
export { Tourmanents }
|
|
@ -3,19 +3,12 @@ from django.db import models
|
|||||||
# Create your models here.
|
# Create your models here.
|
||||||
class GameModel(models.Model):
|
class GameModel(models.Model):
|
||||||
|
|
||||||
finished = models.BooleanField(default=False)
|
|
||||||
started = models.BooleanField(default=False)
|
|
||||||
winner_id = models.IntegerField()
|
|
||||||
|
|
||||||
def create(self, users_id: [int]):
|
def create(self, users_id: [int]):
|
||||||
self.save()
|
self.save()
|
||||||
for user_id in users_id:
|
for user_id in users_id:
|
||||||
GameMembersModel(game_id=self.pk, member_id=user_id).save()
|
GameMembersModel(game_id=self.pk, member_id=user_id)
|
||||||
return self.pk
|
return self.pk
|
||||||
|
|
||||||
def get_users(self):
|
|
||||||
return list(GameMembersModel.objects.filter(self.pk))
|
|
||||||
|
|
||||||
class GameMembersModel(models.Model):
|
class GameMembersModel(models.Model):
|
||||||
game_id = models.IntegerField()
|
game_id = models.IntegerField()
|
||||||
member_id = models.IntegerField()
|
member_id = models.IntegerField()
|
@ -1,3 +0,0 @@
|
|||||||
from django.contrib import admin
|
|
||||||
|
|
||||||
# Register your models here.
|
|
@ -1,6 +0,0 @@
|
|||||||
from django.apps import AppConfig
|
|
||||||
|
|
||||||
|
|
||||||
class TournamentConfig(AppConfig):
|
|
||||||
default_auto_field = 'django.db.models.BigAutoField'
|
|
||||||
name = 'tournament'
|
|
@ -1,47 +0,0 @@
|
|||||||
from django.db import models
|
|
||||||
|
|
||||||
from games.models import GameModel
|
|
||||||
|
|
||||||
# Create your models here.tu
|
|
||||||
class TournamentModel(models.Model):
|
|
||||||
|
|
||||||
name = models.CharField()
|
|
||||||
nb_players = models.IntegerField()
|
|
||||||
nb_players_by_game = models.IntegerField()
|
|
||||||
level = models.IntegerField()
|
|
||||||
started = models.BooleanField(default=False)
|
|
||||||
finished = models.BooleanField(default=False)
|
|
||||||
|
|
||||||
def create(self, nb_players: int, nb_players_by_game: int, name: str = ""):
|
|
||||||
self.level = 1
|
|
||||||
number: int = nb_players
|
|
||||||
while (number != nb_players_by_game):
|
|
||||||
number = number // 2 + (number % 2)
|
|
||||||
self.level += 1
|
|
||||||
self.nb_players = nb_players
|
|
||||||
self.nb_players_by_game = nb_players_by_game
|
|
||||||
self.name = name
|
|
||||||
return self.save()
|
|
||||||
|
|
||||||
def create_game(self, users_id):
|
|
||||||
game_id = GameModel.create(users_id=users_id)
|
|
||||||
TournamentGamesModel(game_id=game_id, tournament_id=self.pk).save()
|
|
||||||
return game_id
|
|
||||||
|
|
||||||
def get_games_id_by_level(self, level):
|
|
||||||
return list(TournamentGamesModel.objects.filter(tournament_id=self.pk, tournament_level=level))
|
|
||||||
|
|
||||||
def get_games_id(self):
|
|
||||||
return list(TournamentGamesModel.objects.filter(tournament_id=self.pk))
|
|
||||||
|
|
||||||
def get_players_id(self):
|
|
||||||
lst: [int] = []
|
|
||||||
for game_id in self.get_games_id():
|
|
||||||
lst.append(GameMembersModel.objects.filter(game_id=game_id))
|
|
||||||
return lst
|
|
||||||
|
|
||||||
class TournamentGamesModel(models.Model):
|
|
||||||
|
|
||||||
tournament_id = models.IntegerField()
|
|
||||||
tournament_level = models.IntegerField()
|
|
||||||
game_id = models.IntegerField()
|
|
@ -1,3 +0,0 @@
|
|||||||
from django.test import TestCase
|
|
||||||
|
|
||||||
# Create your tests here.
|
|
@ -1,10 +0,0 @@
|
|||||||
from django.urls import path
|
|
||||||
from django.conf import settings
|
|
||||||
from django.conf.urls.static import static
|
|
||||||
|
|
||||||
from .views import TournamentsView, TournamentView
|
|
||||||
|
|
||||||
urlpatterns = [
|
|
||||||
path("<int:pk>", name="tournament_page"),
|
|
||||||
path("", TournamentsView.as_view(), name="tournaments"),
|
|
||||||
]
|
|
@ -1,61 +0,0 @@
|
|||||||
from rest_framework.views import APIView
|
|
||||||
from rest_framework.response import Response
|
|
||||||
from rest_framework import permissions, status
|
|
||||||
from rest_framework.authentication import SessionAuthentication
|
|
||||||
|
|
||||||
from django.http import HttpRequest
|
|
||||||
from django.contrib.auth import login
|
|
||||||
|
|
||||||
from matchmaking.models import in_matchmaking
|
|
||||||
from .models import TournamentModel
|
|
||||||
|
|
||||||
# Create your views here.
|
|
||||||
class TournamentsView(APIView):
|
|
||||||
|
|
||||||
permission_classes = (permissions.IsAuthenticated,)
|
|
||||||
authentication_classes = (SessionAuthentication,)
|
|
||||||
|
|
||||||
def post(self, request: HttpRequest):
|
|
||||||
|
|
||||||
data: dict = request.data
|
|
||||||
|
|
||||||
nb_players_by_game = data.get("nb_players_by_game")
|
|
||||||
if (nb_players_by_game is None):
|
|
||||||
return Response("nb_player_by_game is required.", status=status.HTTP_400_BAD_REQUEST)
|
|
||||||
|
|
||||||
nb_players = data.get("nb_players")
|
|
||||||
if (nb_players is None):
|
|
||||||
return Response("nb_players is required.", status=status.HTTP_400_BAD_REQUEST)
|
|
||||||
|
|
||||||
tournament_id: int = TournamentModel.create(users_id=users_id, nb_players=nb_players)
|
|
||||||
|
|
||||||
return Response({"tournament_id": tournament_id}, status=status.HTTP_201_CREATED)
|
|
||||||
|
|
||||||
class TournamentView(APIView):
|
|
||||||
|
|
||||||
permission_classes = (permissions.IsAuthenticated,)
|
|
||||||
authentication_classes = (SessionAuthentication,)
|
|
||||||
|
|
||||||
def get(self, request: HttpRequest, pk):
|
|
||||||
|
|
||||||
if (not TournamentModel.objects.filter(pk=pk).exists()):
|
|
||||||
return Response({"detail": "Tournament not found."}, status=status.HTTP_404_NOT_FOUND)
|
|
||||||
|
|
||||||
tournament = TournamentModel.objects.get(pk=pk)
|
|
||||||
|
|
||||||
levels: [[int]] = []
|
|
||||||
level: [int] = tournament.get_games_id_by_level
|
|
||||||
while level != []:
|
|
||||||
levels.append(level)
|
|
||||||
level: [int] = tournament.get_games_id_by_level
|
|
||||||
|
|
||||||
data = {
|
|
||||||
"name": tournament.name,
|
|
||||||
"finished": tournament.finished,
|
|
||||||
"started": tournament.finished,
|
|
||||||
"nb_players": tournament.nb_players,
|
|
||||||
"nb_players_by_game": tournament.nb_players_by_game,
|
|
||||||
"levels": levels
|
|
||||||
}
|
|
||||||
|
|
||||||
return Response(data, status=status.HTTP_200_OK)
|
|
@ -43,7 +43,6 @@ INSTALLED_APPS = [
|
|||||||
'channels',
|
'channels',
|
||||||
'daphne',
|
'daphne',
|
||||||
|
|
||||||
'tournament.apps.TournamentConfig',
|
|
||||||
'matchmaking.apps.MatchmakingConfig',
|
'matchmaking.apps.MatchmakingConfig',
|
||||||
'games.apps.GamesConfig',
|
'games.apps.GamesConfig',
|
||||||
'accounts.apps.AccountsConfig',
|
'accounts.apps.AccountsConfig',
|
||||||
|
@ -22,6 +22,5 @@ urlpatterns = [
|
|||||||
path('api/profiles/', include('profiles.urls')),
|
path('api/profiles/', include('profiles.urls')),
|
||||||
path('api/accounts/', include('accounts.urls')),
|
path('api/accounts/', include('accounts.urls')),
|
||||||
path('api/chat/', include('chat.urls')),
|
path('api/chat/', include('chat.urls')),
|
||||||
path('api/tournament', include('tournament.urls')),
|
|
||||||
path('', include('frontend.urls')),
|
path('', include('frontend.urls')),
|
||||||
]
|
]
|
||||||
|
Loading…
Reference in New Issue
Block a user