X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=app%2FHttp%2FControllers%2FTournamentController.php;h=fd9aab35d79e91bae3be78889d49885ea740df6c;hb=43da6b2ec78774e7b045a09c68af39717b5f5dbc;hp=e563eac60bfb39c34a58e8da3da5a712a6ad14a6;hpb=1c91e5dcedd930bea5fe44ea95a77a9ecd0177a4;p=alttp.git diff --git a/app/Http/Controllers/TournamentController.php b/app/Http/Controllers/TournamentController.php index e563eac..fd9aab3 100644 --- a/app/Http/Controllers/TournamentController.php +++ b/app/Http/Controllers/TournamentController.php @@ -2,6 +2,10 @@ namespace App\Http\Controllers; +use App\Events\ApplicationAdded; +use App\Events\TournamentChanged; +use App\Models\Application; +use App\Models\Protocol; use App\Models\Tournament; use Illuminate\Auth\Access\AuthorizationException; use Illuminate\Http\Request; @@ -9,8 +13,21 @@ use Illuminate\Http\Request; class TournamentController extends Controller { + public function apply(Request $request, Tournament $tournament) { + $this->authorize('apply', $tournament); + $application = new Application(); + $application->tournament_id = $tournament->id; + $application->user_id = $request->user()->id; + $application->save(); + ApplicationAdded::dispatch($application); + Protocol::applicationReceived($tournament, $application, $request->user()); + return $tournament->toJson(); + } + public function single(Request $request, $id) { $tournament = Tournament::with( + 'applications', + 'applications.user', 'rounds', 'rounds.results', 'participants', @@ -27,4 +44,40 @@ class TournamentController extends Controller return $tournament->toJson(); } + public function open(Request $request, Tournament $tournament) { + $this->authorize('update', $tournament); + $tournament->accept_applications = true; + $tournament->save(); + TournamentChanged::dispatch($tournament); + Protocol::tournamentOpenen($tournament, $request->user()); + return $tournament->toJson(); + } + + public function close(Request $request, Tournament $tournament) { + $this->authorize('update', $tournament); + $tournament->accept_applications = false; + $tournament->save(); + TournamentChanged::dispatch($tournament); + Protocol::tournamentClosed($tournament, $request->user()); + return $tournament->toJson(); + } + + public function lock(Request $request, Tournament $tournament) { + $this->authorize('update', $tournament); + $tournament->locked = true; + $tournament->save(); + TournamentChanged::dispatch($tournament); + Protocol::tournamentLocked($tournament, $request->user()); + return $tournament->toJson(); + } + + public function unlock(Request $request, Tournament $tournament) { + $this->authorize('update', $tournament); + $tournament->locked = false; + $tournament->save(); + TournamentChanged::dispatch($tournament); + Protocol::tournamentUnlocked($tournament, $request->user()); + return $tournament->toJson(); + } + }