X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=app%2FHttp%2FControllers%2FRoundController.php;h=8ec2b84d010eb7519f4e1da796b2e7717e8d1e01;hb=ebdf8e5f6761de2abd85b01096a67dee62d7d4aa;hp=f7e70423f07a987689e03bc5ec15f69f64bc7da4;hpb=8b95f300549d865815d1a5b981844d1296898111;p=alttp.git diff --git a/app/Http/Controllers/RoundController.php b/app/Http/Controllers/RoundController.php index f7e7042..8ec2b84 100644 --- a/app/Http/Controllers/RoundController.php +++ b/app/Http/Controllers/RoundController.php @@ -22,7 +22,9 @@ class RoundController extends Controller $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'], ]); @@ -37,6 +39,38 @@ class RoundController extends Controller return $round->toJson(); } + public function update(Request $request, Round $round) { + $this->authorize('update', $round); + + $validatedData = $request->validate([ + 'code' => 'array', + 'code.*' => 'string', + 'rolled_by' => 'nullable|exists:App\\Models\\User,id', + 'seed' => 'url', + 'spoiler' => 'url', + 'title' => 'string', + ]); + + $round->code = array_filter($validatedData['code']); + $round->rolled_by = $validatedData['rolled_by']; + $round->seed = $validatedData['seed']; + $round->spoiler = $validatedData['spoiler']; + $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); @@ -55,7 +89,45 @@ class RoundController extends Controller RoundChanged::dispatch($round); - $round->load('results'); + $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(); }