]> git.localhorst.tv Git - alttp.git/blob - app/Http/Controllers/TournamentController.php
application admin UI
[alttp.git] / app / Http / Controllers / TournamentController.php
1 <?php
2
3 namespace App\Http\Controllers;
4
5 use App\Events\ApplicationAdded;
6 use App\Models\Application;
7 use App\Models\Protocol;
8 use App\Models\Tournament;
9 use Illuminate\Auth\Access\AuthorizationException;
10 use Illuminate\Http\Request;
11
12 class TournamentController extends Controller
13 {
14
15         public function apply(Request $request, Tournament $tournament) {
16                 $this->authorize('apply', $tournament);
17                 $application = new Application();
18                 $application->tournament_id = $tournament->id;
19                 $application->user_id = $request->user()->id;
20                 $application->save();
21                 ApplicationAdded::dispatch($application);
22                 Protocol::applicationReceived($tournament, $application, $request->user());
23                 return $tournament->toJson();
24         }
25
26         public function single(Request $request, $id) {
27                 $tournament = Tournament::with(
28                         'applications',
29                         'applications.user',
30                         'rounds',
31                         'rounds.results',
32                         'participants',
33                         'participants.user',
34                 )->findOrFail($id);
35                 $this->authorize('view', $tournament);
36                 foreach ($tournament->rounds as $round) {
37                         try {
38                                 $this->authorize('seeResults', $round);
39                         } catch (AuthorizationException) {
40                                 $round->hideResults();
41                         }
42                 }
43                 return $tournament->toJson();
44         }
45
46 }