From 49ff97e2b01d23b598f4839c020c47fa8ce676e0 Mon Sep 17 00:00:00 2001 From: Matt Young Date: Wed, 17 Jul 2024 16:19:30 -0500 Subject: [PATCH] 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 --- app/Actions/Entries/UpdateEntry.php | 3 +++ .../Controllers/Admin/EntryController.php | 19 +++++++++++++------ tests/Feature/Pages/Admin/EntriesEditTest.php | 7 ++++--- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/app/Actions/Entries/UpdateEntry.php b/app/Actions/Entries/UpdateEntry.php index 4d44650..eeb8d90 100644 --- a/app/Actions/Entries/UpdateEntry.php +++ b/app/Actions/Entries/UpdateEntry.php @@ -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']); } diff --git a/app/Http/Controllers/Admin/EntryController.php b/app/Http/Controllers/Admin/EntryController.php index 2edead0..362b9df 100644 --- a/app/Http/Controllers/Admin/EntryController.php +++ b/app/Http/Controllers/Admin/EntryController.php @@ -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'); } diff --git a/tests/Feature/Pages/Admin/EntriesEditTest.php b/tests/Feature/Pages/Admin/EntriesEditTest.php index e9b3fcb..105e245 100644 --- a/tests/Feature/Pages/Admin/EntriesEditTest.php +++ b/tests/Feature/Pages/Admin/EntriesEditTest.php @@ -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