X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=app%2FHttp%2FControllers%2FTournamentController.php;h=f53dad4b644e5aee03481c5e670424ea6e8fe1ac;hb=d518ede5ffe8d4e44b0194279a9f32839bc1f903;hp=2bb258efb0be4de7cba36804cd8021b4e4bd8027;hpb=a58382451a425ebb828ee27c348013de5d4aca67;p=alttp.git diff --git a/app/Http/Controllers/TournamentController.php b/app/Http/Controllers/TournamentController.php index 2bb258e..f53dad4 100644 --- a/app/Http/Controllers/TournamentController.php +++ b/app/Http/Controllers/TournamentController.php @@ -28,20 +28,21 @@ class TournamentController extends Controller $tournament = Tournament::with( 'applications', 'applications.user', - 'rounds', - 'rounds.results', 'participants', 'participants.user', )->findOrFail($id); $this->authorize('view', $tournament); - foreach ($tournament->rounds as $round) { + $rounds = $tournament->rounds()->with(['results', 'results.user'])->limit(25)->get(); + foreach ($rounds as $round) { try { $this->authorize('seeResults', $round); } catch (AuthorizationException) { $round->hideResults(); } } - return $tournament->toJson(); + $json = $tournament->toArray(); + $json['rounds'] = $rounds->toArray(); + return $json; } public function discord(Request $request, Tournament $tournament) { @@ -80,6 +81,27 @@ class TournamentController extends Controller return $tournament->toJson(); } + public function moreRounds(Request $request, Tournament $tournament) { + $this->authorize('view', $tournament); + + $validatedData = $request->validate([ + 'last_known' => 'integer|required', + ]); + + $rounds = $tournament->rounds() + ->where('number', '<', $validatedData['last_known']) + ->with(['results', 'results.user']) + ->limit(25)->get(); + foreach ($rounds as $round) { + try { + $this->authorize('seeResults', $round); + } catch (AuthorizationException) { + $round->hideResults(); + } + } + return $rounds->toArray(); + } + public function open(Request $request, Tournament $tournament) { $this->authorize('update', $tournament); $tournament->accept_applications = true;