]> git.localhorst.tv Git - alttp.git/blobdiff - app/Http/Controllers/RoundController.php
allow setting seeds
[alttp.git] / app / Http / Controllers / RoundController.php
index 10e4d14857fd45000863df2fab536583a8404c6e..d884d544bb22f5bd728e5e2f24859ab81ea6647e 100644 (file)
@@ -2,6 +2,9 @@
 
 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;
@@ -20,6 +23,37 @@ class RoundController extends Controller
                        '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();
        }