]> git.localhorst.tv Git - alttp.git/blobdiff - app/Http/Controllers/RoundController.php
round titles
[alttp.git] / app / Http / Controllers / RoundController.php
index 1488d97bff92e15004407c2bc6493f507761bfcd..2b6c617acfbaa03d93df72544f4881d2036eb812 100644 (file)
@@ -3,6 +3,7 @@
 namespace App\Http\Controllers;
 
 use App\Events\RoundAdded;
+use App\Events\RoundChanged;
 use App\Models\Protocol;
 use App\Models\Round;
 use App\Models\Tournament;
@@ -18,7 +19,12 @@ class RoundController extends Controller
                $tournament = Tournament::findOrFail($validatedData['tournament_id']);
                $this->authorize('addRound', $tournament);
 
+               $tournament->loadMax('rounds', 'number');
+
                $round = Round::create([
+                       'game' => $tournament->game,
+                       'number' => intval($tournament->rounds_max_number) + 1,
+                       'no_record' => $tournament->no_record,
                        'tournament_id' => $validatedData['tournament_id'],
                ]);
 
@@ -33,4 +39,90 @@ class RoundController extends Controller
                return $round->toJson();
        }
 
+       public function update(Request $request, Round $round) {
+               $this->authorize('update', $round);
+
+               $validatedData = $request->validate([
+                       'seed' => 'url',
+                       'title' => 'string',
+               ]);
+
+               $round->seed = $validatedData['seed'];
+               $round->title = $validatedData['title'];
+               $round->update();
+
+               Protocol::roundEdited(
+                       $round->tournament,
+                       $round,
+                       $request->user(),
+               );
+
+               RoundChanged::dispatch($round);
+
+               $round->load(['results', 'results.user']);
+
+               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', 'results.user']);
+
+               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', 'results.user']);
+
+               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', 'results.user']);
+
+               return $round->toJson();
+       }
+
 }