X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=app%2FHttp%2FControllers%2FResultController.php;h=ba57c4b0759f45c33b0bb72fe776ec02cc65a5c7;hb=1d3c8c6a96fc45d839f0e3719baca790059d189f;hp=ab1759d6faaf1bf97fb9c0d5d2c51014a8935d3a;hpb=a4260a00251cef4ad806c9d5c44d4c444d6ab831;p=alttp.git diff --git a/app/Http/Controllers/ResultController.php b/app/Http/Controllers/ResultController.php index ab1759d..ba57c4b 100644 --- a/app/Http/Controllers/ResultController.php +++ b/app/Http/Controllers/ResultController.php @@ -3,10 +3,11 @@ namespace App\Http\Controllers; use App\Events\ResultChanged; -use App\Models\Participant; +use App\Models\DiscordBotCommand; use App\Models\Protocol; use App\Models\Result; use App\Models\Round; +use App\Models\User; use Illuminate\Http\Request; class ResultController extends Controller @@ -16,28 +17,28 @@ class ResultController extends Controller $validatedData = $request->validate([ 'comment' => 'string', 'forfeit' => 'boolean', - 'participant_id' => 'required|exists:App\\Models\\Participant,id', 'round_id' => 'required|exists:App\\Models\\Round,id', 'time' => 'numeric', + 'user_id' => 'required|exists:App\\Models\\User,id', + 'vod' => 'string|url', ]); - $participant = Participant::findOrFail($validatedData['participant_id']); $round = Round::findOrFail($validatedData['round_id']); - $user = $request->user(); - if ($user->id != $participant->user->id) { + if ($validatedData['user_id'] != $request->user()->id) { $this->authorize('create', Result::class); } $result = Result::firstOrCreate([ 'round_id' => $validatedData['round_id'], - 'user_id' => $participant->user_id, + 'user_id' => $validatedData['user_id'], ]); if (!$round->locked) { if (isset($validatedData['forfeit'])) $result->forfeit = $validatedData['forfeit']; if (isset($validatedData['time'])) $result->time = $validatedData['time']; } - $result->comment = $validatedData['comment'] ? $validatedData['comment'] : null; + $result->comment = !empty($validatedData['comment']) ? $validatedData['comment'] : null; + $result->vod = !empty($validatedData['vod']) ? $validatedData['vod'] : null; $result->save(); if ($result->wasChanged()) { @@ -50,7 +51,8 @@ class ResultController extends Controller $result, $request->user(), ); - } else if ($result->wasChanged('comment')) { + DiscordBotCommand::queueResult($result); + } else if ($result->wasChanged(['comment', 'vod'])) { Protocol::resultCommented( $round->tournament, $result, @@ -60,7 +62,11 @@ class ResultController extends Controller $round->load('results'); $round->updatePlacement(); - $round->tournament->updatePlacement(); + if ($round->tournament->hasScoreboard()) { + $round->tournament->updatePlacement(); + } + + $result->load('user'); return $result->toJson(); }