From 55f2d7cd6c290a0d26db177d54d20c393f890bbb Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Wed, 9 Mar 2022 18:33:54 +0100 Subject: [PATCH] add model dummies --- .../Controllers/ParticipantController.php | 10 ++ app/Http/Controllers/ProtocolController.php | 10 ++ app/Http/Controllers/ResultController.php | 10 ++ app/Http/Controllers/RoundController.php | 10 ++ app/Http/Controllers/TournamentController.php | 10 ++ app/Models/Participant.php | 20 ++++ app/Models/Protocol.php | 20 ++++ app/Models/Result.php | 20 ++++ app/Models/Round.php | 20 ++++ app/Models/Tournament.php | 24 +++++ app/Models/User.php | 85 ++++++++--------- app/Policies/ParticipantPolicy.php | 94 +++++++++++++++++++ app/Policies/ProtocolPolicy.php | 94 +++++++++++++++++++ app/Policies/ResultPolicy.php | 94 +++++++++++++++++++ app/Policies/RoundPolicy.php | 94 +++++++++++++++++++ app/Policies/TournamentPolicy.php | 94 +++++++++++++++++++ .../2022_03_09_163037_add_user_role.php | 32 +++++++ ..._03_09_165525_create_tournaments_table.php | 32 +++++++ ...03_09_165535_create_participants_table.php | 33 +++++++ .../2022_03_09_165540_create_rounds_table.php | 33 +++++++ ...2022_03_09_165556_create_results_table.php | 36 +++++++ ...22_03_09_170353_create_protocols_table.php | 35 +++++++ 22 files changed, 868 insertions(+), 42 deletions(-) create mode 100644 app/Http/Controllers/ParticipantController.php create mode 100644 app/Http/Controllers/ProtocolController.php create mode 100644 app/Http/Controllers/ResultController.php create mode 100644 app/Http/Controllers/RoundController.php create mode 100644 app/Http/Controllers/TournamentController.php create mode 100644 app/Models/Participant.php create mode 100644 app/Models/Protocol.php create mode 100644 app/Models/Result.php create mode 100644 app/Models/Round.php create mode 100644 app/Models/Tournament.php create mode 100644 app/Policies/ParticipantPolicy.php create mode 100644 app/Policies/ProtocolPolicy.php create mode 100644 app/Policies/ResultPolicy.php create mode 100644 app/Policies/RoundPolicy.php create mode 100644 app/Policies/TournamentPolicy.php create mode 100644 database/migrations/2022_03_09_163037_add_user_role.php create mode 100644 database/migrations/2022_03_09_165525_create_tournaments_table.php create mode 100644 database/migrations/2022_03_09_165535_create_participants_table.php create mode 100644 database/migrations/2022_03_09_165540_create_rounds_table.php create mode 100644 database/migrations/2022_03_09_165556_create_results_table.php create mode 100644 database/migrations/2022_03_09_170353_create_protocols_table.php diff --git a/app/Http/Controllers/ParticipantController.php b/app/Http/Controllers/ParticipantController.php new file mode 100644 index 0000000..13d7efb --- /dev/null +++ b/app/Http/Controllers/ParticipantController.php @@ -0,0 +1,10 @@ +belongsTo(Tournament::class); + } + + public function user() { + return $this->belongsTo(User::class); + } + +} diff --git a/app/Models/Protocol.php b/app/Models/Protocol.php new file mode 100644 index 0000000..fb93a37 --- /dev/null +++ b/app/Models/Protocol.php @@ -0,0 +1,20 @@ +belongsTo(Tournament::class); + } + + public function user() { + return $this->belongsTo(User::class); + } + +} diff --git a/app/Models/Result.php b/app/Models/Result.php new file mode 100644 index 0000000..e693fc7 --- /dev/null +++ b/app/Models/Result.php @@ -0,0 +1,20 @@ +belongsTo(Round::class); + } + + public function participant() { + return $this->belongsTo(Participant::class); + } + +} diff --git a/app/Models/Round.php b/app/Models/Round.php new file mode 100644 index 0000000..9420692 --- /dev/null +++ b/app/Models/Round.php @@ -0,0 +1,20 @@ +hasMany(Result::class); + } + + public function tournament() { + return $this->belongsTo(Tournament::class); + } + +} diff --git a/app/Models/Tournament.php b/app/Models/Tournament.php new file mode 100644 index 0000000..a19e179 --- /dev/null +++ b/app/Models/Tournament.php @@ -0,0 +1,24 @@ +hasMany(Participant::class); + } + + public function protocols() { + return $this->hasMany(Protocol::class); + } + + public function rounds() { + return $this->hasMany(Round::class); + } + +} diff --git a/app/Models/User.php b/app/Models/User.php index 7f216ed..dd12982 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -10,49 +10,50 @@ use Laravel\Sanctum\HasApiTokens; 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', + ]; } diff --git a/app/Policies/ParticipantPolicy.php b/app/Policies/ParticipantPolicy.php new file mode 100644 index 0000000..f5b5246 --- /dev/null +++ b/app/Policies/ParticipantPolicy.php @@ -0,0 +1,94 @@ +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; + } +} diff --git a/app/Policies/ProtocolPolicy.php b/app/Policies/ProtocolPolicy.php new file mode 100644 index 0000000..186fe09 --- /dev/null +++ b/app/Policies/ProtocolPolicy.php @@ -0,0 +1,94 @@ +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; + } +} diff --git a/app/Policies/ResultPolicy.php b/app/Policies/ResultPolicy.php new file mode 100644 index 0000000..7419431 --- /dev/null +++ b/app/Policies/ResultPolicy.php @@ -0,0 +1,94 @@ +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; + } +} diff --git a/app/Policies/TournamentPolicy.php b/app/Policies/TournamentPolicy.php new file mode 100644 index 0000000..b79f8c1 --- /dev/null +++ b/app/Policies/TournamentPolicy.php @@ -0,0 +1,94 @@ +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; + } +} diff --git a/database/migrations/2022_03_09_163037_add_user_role.php b/database/migrations/2022_03_09_163037_add_user_role.php new file mode 100644 index 0000000..cf4f428 --- /dev/null +++ b/database/migrations/2022_03_09_163037_add_user_role.php @@ -0,0 +1,32 @@ +string('role')->default('user'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('users', function(Blueprint $table) { + $table->dropColumn('role'); + }); + } +}; diff --git a/database/migrations/2022_03_09_165525_create_tournaments_table.php b/database/migrations/2022_03_09_165525_create_tournaments_table.php new file mode 100644 index 0000000..07fe283 --- /dev/null +++ b/database/migrations/2022_03_09_165525_create_tournaments_table.php @@ -0,0 +1,32 @@ +id(); + $table->string('title'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('tournaments'); + } +}; diff --git a/database/migrations/2022_03_09_165535_create_participants_table.php b/database/migrations/2022_03_09_165535_create_participants_table.php new file mode 100644 index 0000000..fe7c212 --- /dev/null +++ b/database/migrations/2022_03_09_165535_create_participants_table.php @@ -0,0 +1,33 @@ +id(); + $table->foreignId('tournament_id')->constrained(); + $table->foreignId('user_id')->constrained(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('participants'); + } +}; diff --git a/database/migrations/2022_03_09_165540_create_rounds_table.php b/database/migrations/2022_03_09_165540_create_rounds_table.php new file mode 100644 index 0000000..24b9dfe --- /dev/null +++ b/database/migrations/2022_03_09_165540_create_rounds_table.php @@ -0,0 +1,33 @@ +id(); + $table->foreignId('tournament_id')->constrained(); + $table->string('seed'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('rounds'); + } +}; diff --git a/database/migrations/2022_03_09_165556_create_results_table.php b/database/migrations/2022_03_09_165556_create_results_table.php new file mode 100644 index 0000000..b08b11b --- /dev/null +++ b/database/migrations/2022_03_09_165556_create_results_table.php @@ -0,0 +1,36 @@ +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'); + } +}; diff --git a/database/migrations/2022_03_09_170353_create_protocols_table.php b/database/migrations/2022_03_09_170353_create_protocols_table.php new file mode 100644 index 0000000..4c77058 --- /dev/null +++ b/database/migrations/2022_03_09_170353_create_protocols_table.php @@ -0,0 +1,35 @@ +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'); + } +}; -- 2.39.2