X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=app%2FHttp%2FControllers%2FRoundController.php;h=f7e70423f07a987689e03bc5ec15f69f64bc7da4;hb=8b95f300549d865815d1a5b981844d1296898111;hp=10e4d14857fd45000863df2fab536583a8404c6e;hpb=edd0e97bfdc544114f30bf4c13a929631c44a555;p=alttp.git diff --git a/app/Http/Controllers/RoundController.php b/app/Http/Controllers/RoundController.php index 10e4d14..f7e7042 100644 --- a/app/Http/Controllers/RoundController.php +++ b/app/Http/Controllers/RoundController.php @@ -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,44 @@ 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(); }