3 namespace App\Http\Controllers;
5 use App\Events\RoundAdded;
6 use App\Events\RoundChanged;
7 use App\Models\Protocol;
9 use App\Models\Tournament;
10 use Illuminate\Http\Request;
12 class RoundController extends Controller
15 public function create(Request $request) {
16 $validatedData = $request->validate([
17 'tournament_id' => 'required|exists:App\\Models\\Tournament,id',
19 $tournament = Tournament::findOrFail($validatedData['tournament_id']);
20 $this->authorize('addRound', $tournament);
22 $tournament->loadMax('rounds', 'number');
24 $round = Round::create([
25 'game' => $tournament->game,
26 'number' => intval($tournament->rounds_max_number) + 1,
27 'no_record' => $tournament->no_record,
28 'tournament_id' => $validatedData['tournament_id'],
37 RoundAdded::dispatch($round);
39 return $round->toJson();
42 public function update(Request $request, Round $round) {
43 $this->authorize('update', $round);
45 $validatedData = $request->validate([
48 'rolled_by' => 'nullable|exists:App\\Models\\User,id',
54 $round->code = array_filter($validatedData['code']);
55 $round->rolled_by = $validatedData['rolled_by'];
56 $round->seed = $validatedData['seed'];
57 $round->spoiler = $validatedData['spoiler'];
58 $round->title = $validatedData['title'];
61 Protocol::roundEdited(
67 RoundChanged::dispatch($round);
69 $round->load(['results', 'results.user']);
71 return $round->toJson();
74 public function setSeed(Request $request, Round $round) {
75 $this->authorize('setSeed', $round);
77 $validatedData = $request->validate([
78 'seed' => 'required|url',
81 $round->seed = $validatedData['seed'];
84 Protocol::roundSeedSet(
90 RoundChanged::dispatch($round);
92 $round->load(['results', 'results.user']);
94 return $round->toJson();
97 public function lock(Request $request, Round $round) {
98 $this->authorize('lock', $round);
100 $round->locked = true;
103 Protocol::roundLocked(
109 RoundChanged::dispatch($round);
111 $round->load(['results', 'results.user']);
113 return $round->toJson();
116 public function unlock(Request $request, Round $round) {
117 $this->authorize('unlock', $round);
119 $round->locked = false;
122 Protocol::roundUnlocked(
128 RoundChanged::dispatch($round);
130 $round->load(['results', 'results.user']);
132 return $round->toJson();