Auditionadmin 20 - Bonus scores are fully functional #25
|
|
@ -19,6 +19,7 @@ class EnterBonusScore
|
|||
|
||||
public function __invoke(User $judge, Entry $entry, int $score): void
|
||||
{
|
||||
|
||||
$getRelatedEntries = App::make(GetBonusScoreRelatedEntries::class);
|
||||
$this->basicValidations($judge, $entry);
|
||||
$this->validateJudgeValidity($judge, $entry, $score);
|
||||
|
|
@ -33,6 +34,7 @@ class EnterBonusScore
|
|||
'score' => $score,
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected function getRelatedEntries(Entry $entry): Collection
|
||||
|
|
|
|||
|
|
@ -2,10 +2,14 @@
|
|||
|
||||
namespace App\Http\Controllers\Tabulation;
|
||||
|
||||
use App\Actions\Tabulation\EnterBonusScore;
|
||||
use App\Actions\Tabulation\GetBonusScoreRelatedEntries;
|
||||
use App\Exceptions\ScoreEntryException;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\BonusScore;
|
||||
use App\Models\Entry;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
use function request;
|
||||
|
||||
|
|
@ -42,9 +46,46 @@ class BonusScoreController extends Controller
|
|||
compact('entry', 'bonusScoreDefinition', 'assignedJudges', 'existingScores', 'relatedEntries'));
|
||||
}
|
||||
|
||||
public function saveEntryBonusScoreSheet()
|
||||
public function saveEntryBonusScoreSheet(Entry $entry, GetBonusScoreRelatedEntries $getRelatedEntries, EnterBonusScore $saveBonusScore)
|
||||
{
|
||||
$validData = request()->validate([
|
||||
'judge_id' => 'required|exists:users,id',
|
||||
'entry_id' => 'required|exists:entries,id',
|
||||
'score' => 'nullable|numeric',
|
||||
]);
|
||||
|
||||
$judge = User::find($validData['judge_id']);
|
||||
$entry = Entry::find($validData['entry_id']);
|
||||
$relatedEntries = $getRelatedEntries($entry);
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
|
||||
// Delete existing bonus scores for the entries by the judge
|
||||
foreach ($relatedEntries as $related) {
|
||||
BonusScore::where('entry_id', $related->id)->where('user_id', $judge->id)->delete();
|
||||
}
|
||||
|
||||
// If no score was submitted, were going to just stop at deleting the scores
|
||||
if (! $validData['score'] == null) {
|
||||
// Set the new score
|
||||
try {
|
||||
$saveBonusScore($judge, $entry, $validData['score']);
|
||||
} catch (ScoreEntryException $ex) {
|
||||
DB::rollBack();
|
||||
|
||||
return redirect()->route('bonus-scores.entryBonusScoreSheet',
|
||||
['entry_id' => $entry->id])->with('error', 'Error entering score - '.$ex->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
DB::commit();
|
||||
} catch (\Exception) {
|
||||
DB::rollBack();
|
||||
|
||||
return redirect()->route('bonus-scores.entryBonusScoreSheet', ['entry_id' => $entry->id])->with('error', 'Error entering score - '.$ex->getMessage());
|
||||
}
|
||||
|
||||
return redirect()->route('bonus-scores.entryBonusScoreSheet', ['entry_id' => $entry->id])->with('success', 'New bonus score entered');
|
||||
}
|
||||
|
||||
public function destroyBonusScore()
|
||||
|
|
|
|||
|
|
@ -46,23 +46,25 @@
|
|||
<x-card.card >
|
||||
<x-card.heading>Enter Score</x-card.heading>
|
||||
<div class="mx-5 border-b text-sm">
|
||||
NOTE: Entering score will delete any existing scores for that entry by that judge
|
||||
<p class="mb-3">NOTE: Entering score will delete any existing scores for that entry by that judge</p>
|
||||
<p>Submitting the form with no score value will delete scores by that judge</p>
|
||||
</div>
|
||||
<x-form.form class="mt-3" method="POST" action="{{route('bonus-scores.saveEntryBonusScoreSheet', $entry)}}">
|
||||
<x-form.select name="judge_id" class="mb-5">
|
||||
<x-form.form class="my-3" method="POST" action="{{route('bonus-scores.saveEntryBonusScoreSheet', $entry)}}" x-data="{ judgeChanged: false }">
|
||||
<x-form.select name="judge_id" class="mb-5" required x-on:change="judgeChanged=true">
|
||||
<x-slot:label>Judge</x-slot:label>
|
||||
<option value="" x-bind:disabled="judgeChanged">Choose Judge</option>
|
||||
@foreach($assignedJudges as $judge)
|
||||
<option value="{{ $judge->id }}">{{ $judge->full_name() }}</option>
|
||||
@endforeach
|
||||
</x-form.select>
|
||||
<x-form.select name="entry_id" class="mb-5">
|
||||
<x-form.select name="entry_id" class="mb-5" required>
|
||||
<x-slot:label>Scored Audition</x-slot:label>
|
||||
@foreach($relatedEntries as $related)
|
||||
<option value="{{$related->id}}" {{$related->id == $entry->id ? 'selected':' '}}>{{ $related->audition->name }}</option>
|
||||
@endforeach
|
||||
</x-form.select>
|
||||
<x-form.field label_text="Score" name="score" type="number" max="{{ $bonusScoreDefinition->max_score }}"/>
|
||||
<x-form.button class="mt-5">Enter Score</x-form.button>
|
||||
<x-form.button class="mt-5" x-show="judgeChanged">Enter Score</x-form.button>
|
||||
</x-form.form>
|
||||
</x-card.card>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Reference in New Issue