X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=app%2FHttp%2FControllers%2FRoundController.php;h=4938b3a04a0bac61c31ccd2d2ba49dd604d2209c;hb=d32516335ea2534e15256c948e9c38d3de40794b;hp=1488d97bff92e15004407c2bc6493f507761bfcd;hpb=4388278823ac8a791641ac1d65fc675e9543b8e8;p=alttp.git diff --git a/app/Http/Controllers/RoundController.php b/app/Http/Controllers/RoundController.php index 1488d97..4938b3a 100644 --- a/app/Http/Controllers/RoundController.php +++ b/app/Http/Controllers/RoundController.php @@ -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,10 @@ 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'], ]); @@ -33,4 +37,65 @@ class RoundController extends Controller 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(); + } + }