+
+ public function create(Request $request) {
+ $validatedData = $request->validate([
+ 'participant_id' => 'required|exists:App\\Models\\Participant,id',
+ 'round_id' => 'required|exists:App\\Models\\Round,id',
+ 'time' => 'required|numeric',
+ ]);
+
+ $participant = Participant::findOrFail($validatedData['participant_id']);
+ $round = Round::findOrFail($validatedData['round_id']);
+
+ $user = $request->user();
+ if ($user->id != $participant->user->id) {
+ $this->authorize('create', Result::class);
+ }
+
+ $result = Result::updateOrCreate([
+ 'round_id' => $validatedData['round_id'],
+ 'user_id' => $participant->user_id,
+ ], [
+ 'time' => $validatedData['time'],
+ ]);
+
+ Protocol::resultReported(
+ $round->tournament,
+ $result,
+ $request->user(),
+ );
+
+ ResultReported::dispatch($result);
+
+ return $result->toJson();
+ }
+