]> git.localhorst.tv Git - alttp.git/blobdiff - app/Http/Controllers/RoundController.php
allow admins to lock/unlock rounds
[alttp.git] / app / Http / Controllers / RoundController.php
index 10e4d14857fd45000863df2fab536583a8404c6e..4938b3a04a0bac61c31ccd2d2ba49dd604d2209c 100644 (file)
@@ -2,6 +2,9 @@
 
 namespace App\Http\Controllers;
 
+use App\Events\RoundAdded;
+use App\Events\RoundChanged;
+use App\Models\Protocol;
 use App\Models\Round;
 use App\Models\Tournament;
 use Illuminate\Http\Request;
@@ -16,10 +19,82 @@ class RoundController extends Controller
                $tournament = Tournament::findOrFail($validatedData['tournament_id']);
                $this->authorize('addRound', $tournament);
 
+               $tournament->loadMax('rounds', 'number');
+
                $round = Round::create([
+                       'number' => intval($tournament->rounds_max_number) + 1,
                        'tournament_id' => $validatedData['tournament_id'],
                ]);
 
+               Protocol::roundAdded(
+                       $tournament,
+                       $round,
+                       $request->user(),
+               );
+
+               RoundAdded::dispatch($round);
+
+               return $round->toJson();
+       }
+
+       public function setSeed(Request $request, Round $round) {
+               $this->authorize('setSeed', $round);
+
+               $validatedData = $request->validate([
+                       'seed' => 'required|url',
+               ]);
+
+               $round->seed = $validatedData['seed'];
+               $round->update();
+
+               Protocol::roundSeedSet(
+                       $round->tournament,
+                       $round,
+                       $request->user(),
+               );
+
+               RoundChanged::dispatch($round);
+
+               $round->load('results');
+
+               return $round->toJson();
+       }
+
+       public function lock(Request $request, Round $round) {
+               $this->authorize('lock', $round);
+
+               $round->locked = true;
+               $round->update();
+
+               Protocol::roundLocked(
+                       $round->tournament,
+                       $round,
+                       $request->user(),
+               );
+
+               RoundChanged::dispatch($round);
+
+               $round->load('results');
+
+               return $round->toJson();
+       }
+
+       public function unlock(Request $request, Round $round) {
+               $this->authorize('unlock', $round);
+
+               $round->locked = false;
+               $round->update();
+
+               Protocol::roundUnlocked(
+                       $round->tournament,
+                       $round,
+                       $request->user(),
+               );
+
+               RoundChanged::dispatch($round);
+
+               $round->load('results');
+
                return $round->toJson();
        }