]> git.localhorst.tv Git - alttp.git/commitdiff
group assignment model
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Thu, 20 Nov 2025 11:55:47 +0000 (12:55 +0100)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Thu, 20 Nov 2025 11:55:47 +0000 (12:55 +0100)
app/Http/Controllers/TournamentController.php
app/Models/GroupAssignment.php [new file with mode: 0644]
database/migrations/2025_11_20_095822_create_group_assignments_table.php [new file with mode: 0644]

index 8e3df16d1915f42fee237109d2c1243e7a1b9b61..b29cb2ecc407df96e8f6714fbb399119d463e168 100644 (file)
@@ -5,6 +5,7 @@ namespace App\Http\Controllers;
 use App\Events\ApplicationAdded;
 use App\Events\TournamentChanged;
 use App\Models\Application;
+use App\Models\GroupAssignment;
 use App\Models\Protocol;
 use App\Models\Tournament;
 use Illuminate\Auth\Access\AuthorizationException;
@@ -45,6 +46,13 @@ class TournamentController extends Controller
                }
                $json = $tournament->toArray();
                $json['rounds'] = $rounds->toArray();
+               if ($request->user()) {
+                       $json['group_assignments'] = GroupAssignment::query()
+                               ->whereBelongsTo($tournament)
+                               ->whereBelongsTo($request->user())
+                               ->get()
+                               ->toArray();
+               }
                return $json;
        }
 
diff --git a/app/Models/GroupAssignment.php b/app/Models/GroupAssignment.php
new file mode 100644 (file)
index 0000000..fd12c72
--- /dev/null
@@ -0,0 +1,17 @@
+<?php
+
+namespace App\Models;
+
+use Illuminate\Database\Eloquent\Model;
+
+class GroupAssignment extends Model {
+
+       public function tournament() {
+               return $this->belongsTo(Tournament::class);
+       }
+
+       public function user() {
+               return $this->belongsTo(User::class);
+       }
+
+}
diff --git a/database/migrations/2025_11_20_095822_create_group_assignments_table.php b/database/migrations/2025_11_20_095822_create_group_assignments_table.php
new file mode 100644 (file)
index 0000000..bef768e
--- /dev/null
@@ -0,0 +1,32 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration {
+
+       /**
+        * Run the migrations.
+        */
+       public function up(): void
+       {
+               Schema::create('group_assignments', function (Blueprint $table) {
+                       $table->id();
+                       $table->foreignId('tournament_id')->constrained();
+                       $table->foreignId('user_id')->constrained();
+                       $table->integer('round_number');
+                       $table->string('group');
+                       $table->timestamps();
+               });
+       }
+
+       /**
+        * Reverse the migrations.
+        */
+       public function down(): void
+       {
+               Schema::dropIfExists('group_assignments');
+       }
+
+};