--- /dev/null
+<?php
+
+namespace App\Http\Controllers;
+
+use Illuminate\Http\Request;
+
+class ParticipantController extends Controller
+{
+ //
+}
--- /dev/null
+<?php
+
+namespace App\Http\Controllers;
+
+use Illuminate\Http\Request;
+
+class ProtocolController extends Controller
+{
+ //
+}
--- /dev/null
+<?php
+
+namespace App\Http\Controllers;
+
+use Illuminate\Http\Request;
+
+class ResultController extends Controller
+{
+ //
+}
--- /dev/null
+<?php
+
+namespace App\Http\Controllers;
+
+use Illuminate\Http\Request;
+
+class RoundController extends Controller
+{
+ //
+}
--- /dev/null
+<?php
+
+namespace App\Http\Controllers;
+
+use Illuminate\Http\Request;
+
+class TournamentController extends Controller
+{
+ //
+}
--- /dev/null
+<?php
+
+namespace App\Models;
+
+use Illuminate\Database\Eloquent\Factories\HasFactory;
+use Illuminate\Database\Eloquent\Model;
+
+class Participant extends Model
+{
+ use HasFactory;
+
+ public function tournament() {
+ return $this->belongsTo(Tournament::class);
+ }
+
+ public function user() {
+ return $this->belongsTo(User::class);
+ }
+
+}
--- /dev/null
+<?php
+
+namespace App\Models;
+
+use Illuminate\Database\Eloquent\Factories\HasFactory;
+use Illuminate\Database\Eloquent\Model;
+
+class Protocol extends Model
+{
+ use HasFactory;
+
+ public function tournament() {
+ return $this->belongsTo(Tournament::class);
+ }
+
+ public function user() {
+ return $this->belongsTo(User::class);
+ }
+
+}
--- /dev/null
+<?php
+
+namespace App\Models;
+
+use Illuminate\Database\Eloquent\Factories\HasFactory;
+use Illuminate\Database\Eloquent\Model;
+
+class Result extends Model
+{
+ use HasFactory;
+
+ public function round() {
+ return $this->belongsTo(Round::class);
+ }
+
+ public function participant() {
+ return $this->belongsTo(Participant::class);
+ }
+
+}
--- /dev/null
+<?php
+
+namespace App\Models;
+
+use Illuminate\Database\Eloquent\Factories\HasFactory;
+use Illuminate\Database\Eloquent\Model;
+
+class Round extends Model
+{
+ use HasFactory;
+
+ public function results() {
+ return $this->hasMany(Result::class);
+ }
+
+ public function tournament() {
+ return $this->belongsTo(Tournament::class);
+ }
+
+}
--- /dev/null
+<?php
+
+namespace App\Models;
+
+use Illuminate\Database\Eloquent\Factories\HasFactory;
+use Illuminate\Database\Eloquent\Model;
+
+class Tournament extends Model
+{
+ use HasFactory;
+
+ public function participants() {
+ return $this->hasMany(Participant::class);
+ }
+
+ public function protocols() {
+ return $this->hasMany(Protocol::class);
+ }
+
+ public function rounds() {
+ return $this->hasMany(Round::class);
+ }
+
+}
class User extends Authenticatable
{
- use HasApiTokens, HasFactory, Notifiable;
+ use HasApiTokens, HasFactory, Notifiable;
- /**
- * The attributes that are mass assignable.
- *
- * @var string[]
- */
- protected $fillable = [
- 'id',
- 'username',
- 'discriminator',
- 'email',
- 'avatar',
- 'verified',
- 'locale',
- 'mfa_enabled',
- 'refresh_token'
- ];
+ /**
+ * The attributes that are mass assignable.
+ *
+ * @var string[]
+ */
+ protected $fillable = [
+ 'id',
+ 'username',
+ 'discriminator',
+ 'email',
+ 'avatar',
+ 'verified',
+ 'locale',
+ 'mfa_enabled',
+ 'refresh_token',
+ 'role',
+ ];
- /**
- * The attributes that should be hidden for serialization.
- *
- * @var array
- */
- protected $hidden = [
- 'refresh_token',
- 'remember_token',
- ];
+ /**
+ * The attributes that should be hidden for serialization.
+ *
+ * @var array
+ */
+ protected $hidden = [
+ 'refresh_token',
+ 'remember_token',
+ ];
- /**
- * The attributes that should be cast.
- *
- * @var array
- */
- protected $casts = [
- 'id' => 'string',
- 'username' => 'string',
- 'discriminator' => 'string',
- 'email' => 'string',
- 'avatar' => 'string',
- 'verified' => 'boolean',
- 'locale' => 'string',
- 'mfa_enabled' => 'boolean',
- 'refresh_token' => 'encrypted',
- ];
+ /**
+ * The attributes that should be cast.
+ *
+ * @var array
+ */
+ protected $casts = [
+ 'id' => 'string',
+ 'username' => 'string',
+ 'discriminator' => 'string',
+ 'email' => 'string',
+ 'avatar' => 'string',
+ 'verified' => 'boolean',
+ 'locale' => 'string',
+ 'mfa_enabled' => 'boolean',
+ 'refresh_token' => 'encrypted',
+ ];
}
--- /dev/null
+<?php
+
+namespace App\Policies;
+
+use App\Models\Participant;
+use App\Models\User;
+use Illuminate\Auth\Access\HandlesAuthorization;
+
+class ParticipantPolicy
+{
+ use HandlesAuthorization;
+
+ /**
+ * Determine whether the user can view any models.
+ *
+ * @param \App\Models\User $user
+ * @return \Illuminate\Auth\Access\Response|bool
+ */
+ public function viewAny(User $user)
+ {
+ return $user->role === 'admin';
+ }
+
+ /**
+ * Determine whether the user can view the model.
+ *
+ * @param \App\Models\User $user
+ * @param \App\Models\Participant $participant
+ * @return \Illuminate\Auth\Access\Response|bool
+ */
+ public function view(User $user, Participant $participant)
+ {
+ return $user->role === 'admin';
+ }
+
+ /**
+ * Determine whether the user can create models.
+ *
+ * @param \App\Models\User $user
+ * @return \Illuminate\Auth\Access\Response|bool
+ */
+ public function create(User $user)
+ {
+ return false;
+ }
+
+ /**
+ * Determine whether the user can update the model.
+ *
+ * @param \App\Models\User $user
+ * @param \App\Models\Participant $participant
+ * @return \Illuminate\Auth\Access\Response|bool
+ */
+ public function update(User $user, Participant $participant)
+ {
+ return $user->role === 'admin';
+ }
+
+ /**
+ * Determine whether the user can delete the model.
+ *
+ * @param \App\Models\User $user
+ * @param \App\Models\Participant $participant
+ * @return \Illuminate\Auth\Access\Response|bool
+ */
+ public function delete(User $user, Participant $participant)
+ {
+ return false;
+ }
+
+ /**
+ * Determine whether the user can restore the model.
+ *
+ * @param \App\Models\User $user
+ * @param \App\Models\Participant $participant
+ * @return \Illuminate\Auth\Access\Response|bool
+ */
+ public function restore(User $user, Participant $participant)
+ {
+ return false;
+ }
+
+ /**
+ * Determine whether the user can permanently delete the model.
+ *
+ * @param \App\Models\User $user
+ * @param \App\Models\Participant $participant
+ * @return \Illuminate\Auth\Access\Response|bool
+ */
+ public function forceDelete(User $user, Participant $participant)
+ {
+ return false;
+ }
+}
--- /dev/null
+<?php
+
+namespace App\Policies;
+
+use App\Models\Protocol;
+use App\Models\User;
+use Illuminate\Auth\Access\HandlesAuthorization;
+
+class ProtocolPolicy
+{
+ use HandlesAuthorization;
+
+ /**
+ * Determine whether the user can view any models.
+ *
+ * @param \App\Models\User $user
+ * @return \Illuminate\Auth\Access\Response|bool
+ */
+ public function viewAny(User $user)
+ {
+ return $user->role === 'admin';
+ }
+
+ /**
+ * Determine whether the user can view the model.
+ *
+ * @param \App\Models\User $user
+ * @param \App\Models\Protocol $protocol
+ * @return \Illuminate\Auth\Access\Response|bool
+ */
+ public function view(User $user, Protocol $protocol)
+ {
+ return $user->role === 'admin';
+ }
+
+ /**
+ * Determine whether the user can create models.
+ *
+ * @param \App\Models\User $user
+ * @return \Illuminate\Auth\Access\Response|bool
+ */
+ public function create(User $user)
+ {
+ return false;
+ }
+
+ /**
+ * Determine whether the user can update the model.
+ *
+ * @param \App\Models\User $user
+ * @param \App\Models\Protocol $protocol
+ * @return \Illuminate\Auth\Access\Response|bool
+ */
+ public function update(User $user, Protocol $protocol)
+ {
+ return false;
+ }
+
+ /**
+ * Determine whether the user can delete the model.
+ *
+ * @param \App\Models\User $user
+ * @param \App\Models\Protocol $protocol
+ * @return \Illuminate\Auth\Access\Response|bool
+ */
+ public function delete(User $user, Protocol $protocol)
+ {
+ return false;
+ }
+
+ /**
+ * Determine whether the user can restore the model.
+ *
+ * @param \App\Models\User $user
+ * @param \App\Models\Protocol $protocol
+ * @return \Illuminate\Auth\Access\Response|bool
+ */
+ public function restore(User $user, Protocol $protocol)
+ {
+ return false;
+ }
+
+ /**
+ * Determine whether the user can permanently delete the model.
+ *
+ * @param \App\Models\User $user
+ * @param \App\Models\Protocol $protocol
+ * @return \Illuminate\Auth\Access\Response|bool
+ */
+ public function forceDelete(User $user, Protocol $protocol)
+ {
+ return false;
+ }
+}
--- /dev/null
+<?php
+
+namespace App\Policies;
+
+use App\Models\Result;
+use App\Models\User;
+use Illuminate\Auth\Access\HandlesAuthorization;
+
+class ResultPolicy
+{
+ use HandlesAuthorization;
+
+ /**
+ * Determine whether the user can view any models.
+ *
+ * @param \App\Models\User $user
+ * @return \Illuminate\Auth\Access\Response|bool
+ */
+ public function viewAny(User $user)
+ {
+ return true;
+ }
+
+ /**
+ * Determine whether the user can view the model.
+ *
+ * @param \App\Models\User $user
+ * @param \App\Models\Result $result
+ * @return \Illuminate\Auth\Access\Response|bool
+ */
+ public function view(User $user, Result $result)
+ {
+ return true;
+ }
+
+ /**
+ * Determine whether the user can create models.
+ *
+ * @param \App\Models\User $user
+ * @return \Illuminate\Auth\Access\Response|bool
+ */
+ public function create(User $user)
+ {
+ return false;
+ }
+
+ /**
+ * Determine whether the user can update the model.
+ *
+ * @param \App\Models\User $user
+ * @param \App\Models\Result $result
+ * @return \Illuminate\Auth\Access\Response|bool
+ */
+ public function update(User $user, Result $result)
+ {
+ return false;
+ }
+
+ /**
+ * Determine whether the user can delete the model.
+ *
+ * @param \App\Models\User $user
+ * @param \App\Models\Result $result
+ * @return \Illuminate\Auth\Access\Response|bool
+ */
+ public function delete(User $user, Result $result)
+ {
+ return false;
+ }
+
+ /**
+ * Determine whether the user can restore the model.
+ *
+ * @param \App\Models\User $user
+ * @param \App\Models\Result $result
+ * @return \Illuminate\Auth\Access\Response|bool
+ */
+ public function restore(User $user, Result $result)
+ {
+ return false;
+ }
+
+ /**
+ * Determine whether the user can permanently delete the model.
+ *
+ * @param \App\Models\User $user
+ * @param \App\Models\Result $result
+ * @return \Illuminate\Auth\Access\Response|bool
+ */
+ public function forceDelete(User $user, Result $result)
+ {
+ return false;
+ }
+}
--- /dev/null
+<?php
+
+namespace App\Policies;
+
+use App\Models\Round;
+use App\Models\User;
+use Illuminate\Auth\Access\HandlesAuthorization;
+
+class RoundPolicy
+{
+ use HandlesAuthorization;
+
+ /**
+ * Determine whether the user can view any models.
+ *
+ * @param \App\Models\User $user
+ * @return \Illuminate\Auth\Access\Response|bool
+ */
+ public function viewAny(User $user)
+ {
+ return true;
+ }
+
+ /**
+ * Determine whether the user can view the model.
+ *
+ * @param \App\Models\User $user
+ * @param \App\Models\Round $round
+ * @return \Illuminate\Auth\Access\Response|bool
+ */
+ public function view(User $user, Round $round)
+ {
+ return true;
+ }
+
+ /**
+ * Determine whether the user can create models.
+ *
+ * @param \App\Models\User $user
+ * @return \Illuminate\Auth\Access\Response|bool
+ */
+ public function create(User $user)
+ {
+ return $user->role === 'admin';
+ }
+
+ /**
+ * Determine whether the user can update the model.
+ *
+ * @param \App\Models\User $user
+ * @param \App\Models\Round $round
+ * @return \Illuminate\Auth\Access\Response|bool
+ */
+ public function update(User $user, Round $round)
+ {
+ return $user->role === 'admin';
+ }
+
+ /**
+ * Determine whether the user can delete the model.
+ *
+ * @param \App\Models\User $user
+ * @param \App\Models\Round $round
+ * @return \Illuminate\Auth\Access\Response|bool
+ */
+ public function delete(User $user, Round $round)
+ {
+ return false;
+ }
+
+ /**
+ * Determine whether the user can restore the model.
+ *
+ * @param \App\Models\User $user
+ * @param \App\Models\Round $round
+ * @return \Illuminate\Auth\Access\Response|bool
+ */
+ public function restore(User $user, Round $round)
+ {
+ return false;
+ }
+
+ /**
+ * Determine whether the user can permanently delete the model.
+ *
+ * @param \App\Models\User $user
+ * @param \App\Models\Round $round
+ * @return \Illuminate\Auth\Access\Response|bool
+ */
+ public function forceDelete(User $user, Round $round)
+ {
+ return false;
+ }
+}
--- /dev/null
+<?php
+
+namespace App\Policies;
+
+use App\Models\Tournament;
+use App\Models\User;
+use Illuminate\Auth\Access\HandlesAuthorization;
+
+class TournamentPolicy
+{
+ use HandlesAuthorization;
+
+ /**
+ * Determine whether the user can view any models.
+ *
+ * @param \App\Models\User $user
+ * @return \Illuminate\Auth\Access\Response|bool
+ */
+ public function viewAny(User $user)
+ {
+ return true;
+ }
+
+ /**
+ * Determine whether the user can view the model.
+ *
+ * @param \App\Models\User $user
+ * @param \App\Models\Tournament $tournament
+ * @return \Illuminate\Auth\Access\Response|bool
+ */
+ public function view(User $user, Tournament $tournament)
+ {
+ return true;
+ }
+
+ /**
+ * Determine whether the user can create models.
+ *
+ * @param \App\Models\User $user
+ * @return \Illuminate\Auth\Access\Response|bool
+ */
+ public function create(User $user)
+ {
+ return $user->role === 'admin';
+ }
+
+ /**
+ * Determine whether the user can update the model.
+ *
+ * @param \App\Models\User $user
+ * @param \App\Models\Tournament $tournament
+ * @return \Illuminate\Auth\Access\Response|bool
+ */
+ public function update(User $user, Tournament $tournament)
+ {
+ return $user->role === 'admin';
+ }
+
+ /**
+ * Determine whether the user can delete the model.
+ *
+ * @param \App\Models\User $user
+ * @param \App\Models\Tournament $tournament
+ * @return \Illuminate\Auth\Access\Response|bool
+ */
+ public function delete(User $user, Tournament $tournament)
+ {
+ return false;
+ }
+
+ /**
+ * Determine whether the user can restore the model.
+ *
+ * @param \App\Models\User $user
+ * @param \App\Models\Tournament $tournament
+ * @return \Illuminate\Auth\Access\Response|bool
+ */
+ public function restore(User $user, Tournament $tournament)
+ {
+ return false;
+ }
+
+ /**
+ * Determine whether the user can permanently delete the model.
+ *
+ * @param \App\Models\User $user
+ * @param \App\Models\Tournament $tournament
+ * @return \Illuminate\Auth\Access\Response|bool
+ */
+ public function forceDelete(User $user, Tournament $tournament)
+ {
+ return false;
+ }
+}
--- /dev/null
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration
+{
+ /**
+ * Run the migrations.
+ *
+ * @return void
+ */
+ public function up()
+ {
+ Schema::table('users', function(Blueprint $table) {
+ $table->string('role')->default('user');
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ *
+ * @return void
+ */
+ public function down()
+ {
+ Schema::table('users', function(Blueprint $table) {
+ $table->dropColumn('role');
+ });
+ }
+};
--- /dev/null
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration
+{
+ /**
+ * Run the migrations.
+ *
+ * @return void
+ */
+ public function up()
+ {
+ Schema::create('tournaments', function (Blueprint $table) {
+ $table->id();
+ $table->string('title');
+ $table->timestamps();
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ *
+ * @return void
+ */
+ public function down()
+ {
+ Schema::dropIfExists('tournaments');
+ }
+};
--- /dev/null
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration
+{
+ /**
+ * Run the migrations.
+ *
+ * @return void
+ */
+ public function up()
+ {
+ Schema::create('participants', function (Blueprint $table) {
+ $table->id();
+ $table->foreignId('tournament_id')->constrained();
+ $table->foreignId('user_id')->constrained();
+ $table->timestamps();
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ *
+ * @return void
+ */
+ public function down()
+ {
+ Schema::dropIfExists('participants');
+ }
+};
--- /dev/null
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration
+{
+ /**
+ * Run the migrations.
+ *
+ * @return void
+ */
+ public function up()
+ {
+ Schema::create('rounds', function (Blueprint $table) {
+ $table->id();
+ $table->foreignId('tournament_id')->constrained();
+ $table->string('seed');
+ $table->timestamps();
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ *
+ * @return void
+ */
+ public function down()
+ {
+ Schema::dropIfExists('rounds');
+ }
+};
--- /dev/null
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration
+{
+ /**
+ * Run the migrations.
+ *
+ * @return void
+ */
+ public function up()
+ {
+ Schema::create('results', function (Blueprint $table) {
+ $table->id();
+ $table->foreignId('round_id')->constrained();
+ $table->foreignId('user_id')->constrained();
+ $table->double('time');
+ $table->timestamps();
+
+ $table->unique(['round_id', 'user_id']);
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ *
+ * @return void
+ */
+ public function down()
+ {
+ Schema::dropIfExists('results');
+ }
+};
--- /dev/null
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration
+{
+ /**
+ * Run the migrations.
+ *
+ * @return void
+ */
+ public function up()
+ {
+ Schema::create('protocols', function (Blueprint $table) {
+ $table->id();
+ $table->foreignId('tournament_id')->constrained();
+ $table->foreignId('user_id')->nullable()->constrained();
+ $table->string('type');
+ $table->text('details');
+ $table->timestamps();
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ *
+ * @return void
+ */
+ public function down()
+ {
+ Schema::dropIfExists('protocols');
+ }
+};