X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=app%2FHttp%2FControllers%2FRoundController.php;h=2b6c617acfbaa03d93df72544f4881d2036eb812;hb=4f4b2fd64141cbbff953881e2705602a00b85df5;hp=a6754ed6474da595069316247d38e5055fcdafbf;hpb=55f2d7cd6c290a0d26db177d54d20c393f890bbb;p=alttp.git diff --git a/app/Http/Controllers/RoundController.php b/app/Http/Controllers/RoundController.php index a6754ed..2b6c617 100644 --- a/app/Http/Controllers/RoundController.php +++ b/app/Http/Controllers/RoundController.php @@ -2,9 +2,127 @@ 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; class RoundController extends Controller { - // + + public function create(Request $request) { + $validatedData = $request->validate([ + 'tournament_id' => 'required|exists:App\\Models\\Tournament,id', + ]); + $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'], + ]); + + Protocol::roundAdded( + $tournament, + $round, + $request->user(), + ); + + RoundAdded::dispatch($round); + + 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(); + } + }