X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=app%2FHttp%2FControllers%2FTournamentController.php;h=9b21736d8ea4a111eece00198e6cd858ca856773;hb=537b998e8059c56e3a20ee2a89d42c3bbfbb80b8;hp=9d62c23bac3475f2becac58caca85296756c68bc;hpb=3a774bb649734fc3a2135ec1b52cef9a049880ee;p=alttp.git diff --git a/app/Http/Controllers/TournamentController.php b/app/Http/Controllers/TournamentController.php index 9d62c23..9b21736 100644 --- a/app/Http/Controllers/TournamentController.php +++ b/app/Http/Controllers/TournamentController.php @@ -3,7 +3,9 @@ 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; @@ -18,6 +20,7 @@ class TournamentController extends Controller $application->user_id = $request->user()->id; $application->save(); ApplicationAdded::dispatch($application); + Protocol::applicationReceived($tournament, $application, $request->user()); return $tournament->toJson(); } @@ -27,6 +30,7 @@ class TournamentController extends Controller 'applications.user', 'rounds', 'rounds.results', + 'rounds.results.user', 'participants', 'participants.user', )->findOrFail($id); @@ -41,4 +45,76 @@ class TournamentController extends Controller return $tournament->toJson(); } + public function discord(Request $request, Tournament $tournament) { + $this->authorize('update', $tournament); + $validatedData = $request->validate([ + 'guild_id' => 'string|nullable', + ]); + if (array_key_exists('guild_id', $validatedData)) { + $tournament->discord = $validatedData['guild_id']; + } + $tournament->save(); + if ($tournament->wasChanged()) { + TournamentChanged::dispatch($tournament); + Protocol::tournamentDiscord($tournament, $request->user()); + } + return $tournament->toJson(); + } + + public function discordSettings(Request $request, Tournament $tournament) { + $this->authorize('update', $tournament); + $validatedData = $request->validate([ + 'round_category' => 'string|nullable', + 'round_template' => 'string|nullable', + ]); + if (array_key_exists('round_category', $validatedData)) { + $tournament->discord_round_category = $validatedData['round_category']; + } + if (array_key_exists('round_template', $validatedData)) { + $tournament->discord_round_template = $validatedData['round_template']; + } + $tournament->save(); + if ($tournament->wasChanged()) { + TournamentChanged::dispatch($tournament); + Protocol::tournamentDiscordSettings($tournament, $request->user()); + } + return $tournament->toJson(); + } + + public function open(Request $request, Tournament $tournament) { + $this->authorize('update', $tournament); + $tournament->accept_applications = true; + $tournament->save(); + TournamentChanged::dispatch($tournament); + Protocol::tournamentOpened($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(); + } + }