Use UpdateEntry action on admin edit entry screen

#29 Creating an entry should check on the status of the draw and respond appropriately
Also changed name of CreateEntryException to MangeEntryException

Closes #29
Closes #37
This commit is contained in:
Matt Young 2024-07-17 16:19:30 -05:00
parent 12c37b6250
commit 49ff97e2b0
3 changed files with 20 additions and 9 deletions

View File

@ -42,6 +42,9 @@ class UpdateEntry
if (array_key_exists('for_advancement', $updateData)) {
$this->updateForAdvancement($updateData['for_advancement']);
}
if (array_key_exists('audition_id', $updateData)) {
$this->updateAudition($updateData['audition_id']);
}
if (array_key_exists('audition', $updateData)) {
$this->updateAudition($updateData['audition']);
}

View File

@ -3,6 +3,7 @@
namespace App\Http\Controllers\Admin;
use App\Actions\Entries\CreateEntry;
use App\Actions\Entries\UpdateEntry;
use App\Actions\Tabulation\CalculateEntryScore;
use App\Exceptions\ManageEntryException;
use App\Http\Controllers\Controller;
@ -139,7 +140,7 @@ class EntryController extends Controller
return view('admin.entries.edit', compact('entry', 'students', 'auditions', 'scores'));
}
public function update(Request $request, Entry $entry)
public function update(Request $request, Entry $entry, UpdateEntry $updater)
{
if ($entry->audition->hasFlag('seats_published')) {
return to_route('admin.entries.index')->with('error',
@ -157,15 +158,21 @@ class EntryController extends Controller
$validData['for_seating'] = $request->get('for_seating') ? 1 : 0;
$validData['for_advancement'] = $request->get('for_advancement') ? 1 : 0;
// If the audition is not set to advance to the next round, then the entry must be for seating
if (! auditionSetting('advanceTo')) {
$validData['for_seating'] = 1;
}
try {
$updater($entry, $validData);
} catch (ManageEntryException $e) {
return redirect()->route('admin.entries.index')->with('error', $e->getMessage());
}
$entry->update([
'audition_id' => $validData['audition_id'],
'for_seating' => $validData['for_seating'],
'for_advancement' => $validData['for_advancement'],
]);
// $entry->update([
// 'audition_id' => $validData['audition_id'],
// 'for_seating' => $validData['for_seating'],
// 'for_advancement' => $validData['for_advancement'],
// ]);
return to_route('admin.entries.index')->with('success', 'Entry updated successfully');
}

View File

@ -137,12 +137,13 @@ it('does not let a normal user update an entry', function () {
});
it('allows an admin to update an entry', function () {
// Arrange
$newAudition = Audition::factory()->create();
$newAudition = Audition::factory()->create(['minimum_grade' => 1, 'maximum_grade' => 20]);
actAsAdmin();
// Act & Assert
/** @noinspection PhpUnhandledExceptionInspection */
patch(route('admin.entries.update', $this->entry), ['audition_id' => $newAudition->id])
->assertSessionHasNoErrors()
->assertSessionMissing('error')
->assertSessionHas('success', 'Entry updated successfully')
->assertRedirect(route('admin.entries.index'));
$this->entry->refresh();
@ -221,7 +222,7 @@ it('displays scores', function () {
$response->assertSee($subscore->name);
}
});
it('has a link to delete scores', function() {
it('has a link to delete scores', function () {
// Arrange
$sg = ScoringGuide::factory()->create();
SubscoreDefinition::factory()->count(5)->create(['scoring_guide_id' => $sg->id]);
@ -236,7 +237,7 @@ it('has a link to delete scores', function() {
$scoreSheet = ScoreSheet::where('entry_id', $entry->id)->first();
actAsAdmin();
$response = get(route('admin.entries.edit', $entry))
->assertSee(route('scores.destroy', ['score'=>$scoreSheet]));
->assertSee(route('scores.destroy', ['score' => $scoreSheet]));
});
// Delete tests