X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=app%2FHttp%2FControllers%2FResultController.php;fp=app%2FHttp%2FControllers%2FResultController.php;h=57f78a157f2d1537cebc3bee96626cd629271a12;hb=537b998e8059c56e3a20ee2a89d42c3bbfbb80b8;hp=8698e19838aef615ee45b3ec5f4579ba58bb88d1;hpb=3e970c52e6a46cf9db4f69c5bec9102da53c0744;p=alttp.git diff --git a/app/Http/Controllers/ResultController.php b/app/Http/Controllers/ResultController.php index 8698e19..57f78a1 100644 --- a/app/Http/Controllers/ResultController.php +++ b/app/Http/Controllers/ResultController.php @@ -4,10 +4,10 @@ namespace App\Http\Controllers; use App\Events\ResultChanged; use App\Models\DiscordBotCommand; -use App\Models\Participant; use App\Models\Protocol; use App\Models\Result; use App\Models\Round; +use App\Models\User; use Illuminate\Http\Request; class ResultController extends Controller @@ -17,22 +17,20 @@ 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', ]); - $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']; @@ -62,7 +60,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(); }