]> git.localhorst.tv Git - alttp.git/blobdiff - app/Http/Controllers/RoundController.php
autonumber rounds
[alttp.git] / app / Http / Controllers / RoundController.php
index a6754ed6474da595069316247d38e5055fcdafbf..f7e70423f07a987689e03bc5ec15f69f64bc7da4 100644 (file)
@@ -2,9 +2,62 @@
 
 namespace App\Http\Controllers;
 
+use App\Events\RoundAdded;
+use App\Events\RoundChanged;
+use App\Models\Protocol;
+use App\Models\Round;
+use App\Models\Tournament;
 use Illuminate\Http\Request;
 
 class RoundController extends Controller
 {
-       //
+
+       public function create(Request $request) {
+               $validatedData = $request->validate([
+                       'tournament_id' => 'required|exists:App\\Models\\Tournament,id',
+               ]);
+               $tournament = Tournament::findOrFail($validatedData['tournament_id']);
+               $this->authorize('addRound', $tournament);
+
+               $tournament->loadMax('rounds', 'number');
+
+               $round = Round::create([
+                       'number' => intval($tournament->rounds_max_number) + 1,
+                       'tournament_id' => $validatedData['tournament_id'],
+               ]);
+
+               Protocol::roundAdded(
+                       $tournament,
+                       $round,
+                       $request->user(),
+               );
+
+               RoundAdded::dispatch($round);
+
+               return $round->toJson();
+       }
+
+       public function setSeed(Request $request, Round $round) {
+               $this->authorize('setSeed', $round);
+
+               $validatedData = $request->validate([
+                       'seed' => 'required|url',
+               ]);
+
+               $round->seed = $validatedData['seed'];
+               $round->update();
+
+               Protocol::roundSeedSet(
+                       $round->tournament,
+                       $round,
+                       $request->user(),
+               );
+
+               RoundChanged::dispatch($round);
+
+               $round->load('results');
+
+               return $round->toJson();
+       }
+
 }