]> git.localhorst.tv Git - alttp.git/blobdiff - app/Http/Controllers/TournamentController.php
simple result hiding on initial tournament request
[alttp.git] / app / Http / Controllers / TournamentController.php
index edf6d120f7403ad198c3332bf11db712d12be89c..e563eac60bfb39c34a58e8da3da5a712a6ad14a6 100644 (file)
@@ -2,9 +2,29 @@
 
 namespace App\Http\Controllers;
 
+use App\Models\Tournament;
+use Illuminate\Auth\Access\AuthorizationException;
 use Illuminate\Http\Request;
 
 class TournamentController extends Controller
 {
-       //
+
+       public function single(Request $request, $id) {
+               $tournament = Tournament::with(
+                       'rounds',
+                       'rounds.results',
+                       'participants',
+                       'participants.user',
+               )->findOrFail($id);
+               $this->authorize('view', $tournament);
+               foreach ($tournament->rounds as $round) {
+                       try {
+                               $this->authorize('seeResults', $round);
+                       } catch (AuthorizationException) {
+                               $round->hideResults();
+                       }
+               }
+               return $tournament->toJson();
+       }
+
 }