diff --git a/backend/api/__init__.py b/backend/api/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/backend/api/admin.py b/backend/api/admin.py new file mode 100644 index 0000000..023e1c5 --- /dev/null +++ b/backend/api/admin.py @@ -0,0 +1,11 @@ +from django.contrib import admin + +from api.models import * + +# Register your models here. + +admin.site.register(Team) +admin.site.register(Player) +admin.site.register(PlayerInfo) +admin.site.register(PlayerInfo_Team) +admin.site.register(PlayerRole) diff --git a/backend/api/apps.py b/backend/api/apps.py new file mode 100644 index 0000000..66656fd --- /dev/null +++ b/backend/api/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class ApiConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'api' diff --git a/backend/api/migrations/0001_initial.py b/backend/api/migrations/0001_initial.py new file mode 100644 index 0000000..fff5632 --- /dev/null +++ b/backend/api/migrations/0001_initial.py @@ -0,0 +1,70 @@ +# Generated by Django 5.1.2 on 2024-10-24 01:56 + +import django.db.models.deletion +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Player', + fields=[ + ('steam_id', models.BigIntegerField(primary_key=True, serialize=False)), + ('name', models.CharField(max_length=63)), + ], + ), + migrations.CreateModel( + name='PlayerInfo_Team', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('team_role', models.CharField(choices=[('PL', 'Player'), ('CM', 'Coach/Mentor'), ('TC', 'Team Captain')], default='PL', max_length=2)), + ('created_at', models.DateTimeField(auto_now_add=True)), + ], + ), + migrations.CreateModel( + name='Team', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('team_name', models.CharField(max_length=63)), + ], + ), + migrations.CreateModel( + name='PlayerInfo', + fields=[ + ('player', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, primary_key=True, serialize=False, to='api.player')), + ], + ), + migrations.CreateModel( + name='PlayerRole', + fields=[ + ('playerinfo_team', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, primary_key=True, serialize=False, to='api.playerinfo_team')), + ('player_role', models.CharField(choices=[('P_SCOUT', 'Pocket Scout'), ('F_SCOUT', 'Flank Scout'), ('SCOUT', 'Scout'), ('P_SOLLY', 'Pocket Soldier'), ('ROAMER', 'Roamer'), ('SOLDIER', 'Soldier'), ('PYRO', 'Pyro'), ('DEMO', 'Demoman'), ('HEAVY', 'Heavy'), ('ENGIE', 'Engineer'), ('MEDIC', 'Medic'), ('SNIPER', 'Sniper'), ('SPY', 'Spy')], max_length=7)), + ('main', models.BooleanField(default=True)), + ], + ), + migrations.AddField( + model_name='playerinfo_team', + name='team', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='api.team'), + ), + migrations.AddField( + model_name='playerinfo_team', + name='player_info', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='api.playerinfo'), + ), + migrations.AddField( + model_name='playerinfo', + name='team', + field=models.ManyToManyField(through='api.PlayerInfo_Team', to='api.team'), + ), + migrations.AlterUniqueTogether( + name='playerinfo_team', + unique_together={('player_info', 'team')}, + ), + ] diff --git a/backend/api/migrations/0002_alter_playerinfo_team_team_role.py b/backend/api/migrations/0002_alter_playerinfo_team_team_role.py new file mode 100644 index 0000000..3ea0596 --- /dev/null +++ b/backend/api/migrations/0002_alter_playerinfo_team_team_role.py @@ -0,0 +1,18 @@ +# Generated by Django 5.1.2 on 2024-10-24 02:00 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('api', '0001_initial'), + ] + + operations = [ + migrations.AlterField( + model_name='playerinfo_team', + name='team_role', + field=models.CharField(choices=[('PL', 'Player'), ('CM', 'Coach/Mentor'), ('TL', 'Team Leader')], default='PL', max_length=2), + ), + ] diff --git a/backend/api/migrations/0003_playermasteravailability_playerteamavailability.py b/backend/api/migrations/0003_playermasteravailability_playerteamavailability.py new file mode 100644 index 0000000..c030f5f --- /dev/null +++ b/backend/api/migrations/0003_playermasteravailability_playerteamavailability.py @@ -0,0 +1,36 @@ +# Generated by Django 5.1.2 on 2024-10-24 02:18 + +import django.db.models.deletion +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('api', '0002_alter_playerinfo_team_team_role'), + ] + + operations = [ + migrations.CreateModel( + name='PlayerMasterAvailability', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('start_time', models.DateTimeField()), + ('playerinfo', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='api.playerinfo')), + ], + options={ + 'constraints': [models.UniqueConstraint(fields=('playerinfo', 'start_time'), name='unique_master_availability')], + }, + ), + migrations.CreateModel( + name='PlayerTeamAvailability', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('start_time', models.DateTimeField()), + ('playerinfo_team', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='api.playerinfo_team')), + ], + options={ + 'constraints': [models.UniqueConstraint(fields=('playerinfo_team', 'start_time'), name='unique_team_availability')], + }, + ), + ] diff --git a/backend/api/migrations/0004_remove_playermasteravailability_unique_master_availability_and_more.py b/backend/api/migrations/0004_remove_playermasteravailability_unique_master_availability_and_more.py new file mode 100644 index 0000000..e2b1caa --- /dev/null +++ b/backend/api/migrations/0004_remove_playermasteravailability_unique_master_availability_and_more.py @@ -0,0 +1,39 @@ +# Generated by Django 5.1.2 on 2024-10-24 02:21 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('api', '0003_playermasteravailability_playerteamavailability'), + ] + + operations = [ + migrations.RemoveConstraint( + model_name='playermasteravailability', + name='unique_master_availability', + ), + migrations.RemoveConstraint( + model_name='playerteamavailability', + name='unique_team_availability', + ), + migrations.RenameField( + model_name='playermasteravailability', + old_name='playerinfo', + new_name='player_info', + ), + migrations.RenameField( + model_name='playerteamavailability', + old_name='playerinfo_team', + new_name='player_info_team', + ), + migrations.AddConstraint( + model_name='playermasteravailability', + constraint=models.UniqueConstraint(fields=('player_info', 'start_time'), name='unique_master_availability'), + ), + migrations.AddConstraint( + model_name='playerteamavailability', + constraint=models.UniqueConstraint(fields=('player_info_team', 'start_time'), name='unique_team_availability'), + ), + ] diff --git a/backend/api/migrations/__init__.py b/backend/api/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/backend/api/models.py b/backend/api/models.py new file mode 100644 index 0000000..a3fa80c --- /dev/null +++ b/backend/api/models.py @@ -0,0 +1,121 @@ +from typing import override +from django.db import models +from cpkmodel import CPkModel +from django.db.models.constraints import UniqueConstraint + +class Team(models.Model): + team_name = models.CharField(max_length=63) + + @override + def __str__(self) -> str: + return str(self.team_name) + +class Player(models.Model): + steam_id = models.BigIntegerField(primary_key=True) + name = models.CharField(max_length=63) + + @override + def __str__(self) -> str: + return f"{self.name}#{self.steam_id}" + +class PlayerInfo(models.Model): + player = models.OneToOneField( + Player, + on_delete=models.CASCADE, + null=False, + primary_key=True + ) + team = models.ManyToManyField(Team, through="PlayerInfo_Team") + + @override + def __str__(self) -> str: + return str(self.player) + +class PlayerInfo_Team(models.Model): + class TeamRole(models.TextChoices): + PLAYER = "PL", "Player" + COACH_MENTOR = "CM", "Coach/Mentor" + TEAM_LEADER = "TL", "Team Leader" + + player_info = models.ForeignKey(PlayerInfo, on_delete=models.CASCADE) + team = models.ForeignKey(Team, on_delete=models.CASCADE, null=True) + team_role = models.CharField( + max_length=2, + choices=TeamRole.choices, + default=TeamRole.PLAYER + ) + created_at = models.DateTimeField(auto_now_add=True) + + @override + def __str__(self) -> str: + return f"{self.player_info} in {self.team} as {self.team_role}" + + class Meta: + unique_together = (("player_info", "team"),) + +class PlayerRole(models.Model): + class Role(models.TextChoices): + P_SCOUT = "P_SCOUT", "Pocket Scout" + F_SCOUT = "F_SCOUT", "Flank Scout" + SCOUT = "SCOUT", "Scout" + + P_SOLLY = "P_SOLLY", "Pocket Soldier" + ROAMER = "ROAMER", "Roamer" + SOLDIER = "SOLDIER", "Soldier" + + PYRO = "PYRO", "Pyro" + DEMO = "DEMO", "Demoman" + HEAVY = "HEAVY", "Heavy" + ENGIE = "ENGIE", "Engineer" + MEDIC = "MEDIC", "Medic" + SNIPER = "SNIPER", "Sniper" + SPY = "SPY", "Spy" + + playerinfo_team = models.ForeignKey( + PlayerInfo_Team, + on_delete=models.CASCADE, + primary_key=True, + ) + player_role = models.CharField( + max_length=7, + choices=Role.choices, + ) + main = models.BooleanField(default=True) + + @override + def __str__(self) -> str: + return f"{self.playerinfo_team.player_info} ({self.player_role} for {self.playerinfo_team.team})" + +class PlayerTeamAvailability(models.Model): + player_info_team = models.ForeignKey(PlayerInfo_Team, on_delete=models.CASCADE) + date = models.DateField() + hour = models.SmallIntegerField() + + class Meta: + constraints = [ + UniqueConstraint(fields=[ + "player_info_team", + "start_time" + ], name="unique_team_availability") + ] + + @override + def __str__(self) -> str: + return f"{self.player_info_team} available on {self.start_time}" + +class PlayerMasterAvailability(models.Model): + player_info = models.ForeignKey(PlayerInfo, on_delete=models.CASCADE) + date = models.DateField() + hour = models.SmallIntegerField() + + class Meta: + constraints = [ + UniqueConstraint(fields=[ + "player_info", + "start_time" + ], name="unique_master_availability") + ] + + @override + def __str__(self) -> str: + return f"{self.player_info} available on {self.start_time}" diff --git a/backend/api/tests.py b/backend/api/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/backend/api/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/backend/api/views.py b/backend/api/views.py new file mode 100644 index 0000000..91ea44a --- /dev/null +++ b/backend/api/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. diff --git a/backend/availabili_tf/settings.py b/backend/availabili_tf/settings.py index 521cad8..f1c6796 100644 --- a/backend/availabili_tf/settings.py +++ b/backend/availabili_tf/settings.py @@ -37,6 +37,8 @@ INSTALLED_APPS = [ 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', + 'rest_framework', + 'api', ] MIDDLEWARE = [ diff --git a/backend/availabili_tf/urls.py b/backend/availabili_tf/urls.py index 3aa1e7a..e59b179 100644 --- a/backend/availabili_tf/urls.py +++ b/backend/availabili_tf/urls.py @@ -18,5 +18,6 @@ from django.contrib import admin from django.urls import path urlpatterns = [ - path('admin/', admin.site.urls), + path("admin/", admin.site.urls), + path("/", admin.site.urls), ]