]> git.localhorst.tv Git - alttp.git/blob - app/Http/Controllers/RoundController.php
allow setting seeds
[alttp.git] / app / Http / Controllers / RoundController.php
1 <?php
2
3 namespace App\Http\Controllers;
4
5 use App\Events\RoundAdded;
6 use App\Events\RoundChanged;
7 use App\Models\Protocol;
8 use App\Models\Round;
9 use App\Models\Tournament;
10 use Illuminate\Http\Request;
11
12 class RoundController extends Controller
13 {
14
15         public function create(Request $request) {
16                 $validatedData = $request->validate([
17                         'tournament_id' => 'required|exists:App\\Models\\Tournament,id',
18                 ]);
19                 $tournament = Tournament::findOrFail($validatedData['tournament_id']);
20                 $this->authorize('addRound', $tournament);
21
22                 $round = Round::create([
23                         'tournament_id' => $validatedData['tournament_id'],
24                 ]);
25
26                 Protocol::roundAdded(
27                         $tournament,
28                         $round,
29                         $request->user(),
30                 );
31
32                 RoundAdded::dispatch($round);
33
34                 return $round->toJson();
35         }
36
37         public function setSeed(Request $request, Round $round) {
38                 $this->authorize('setSeed', $round);
39
40                 $validatedData = $request->validate([
41                         'seed' => 'required|url',
42                 ]);
43
44                 $round->seed = $validatedData['seed'];
45                 $round->update();
46
47                 Protocol::roundSeedSet(
48                         $round->tournament,
49                         $round,
50                         $request->user(),
51                 );
52
53                 RoundChanged::dispatch($round);
54
55                 $round->load('results');
56
57                 return $round->toJson();
58         }
59
60 }