Auditionadmin 29 #40

Merged
okorpheus merged 5 commits from auditionadmin-29 into master 2024-07-17 21:22:23 +00:00
3 changed files with 20 additions and 9 deletions
Showing only changes of commit 49ff97e2b0 - Show all commits

View File

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

View File

@ -3,6 +3,7 @@
namespace App\Http\Controllers\Admin; namespace App\Http\Controllers\Admin;
use App\Actions\Entries\CreateEntry; use App\Actions\Entries\CreateEntry;
use App\Actions\Entries\UpdateEntry;
use App\Actions\Tabulation\CalculateEntryScore; use App\Actions\Tabulation\CalculateEntryScore;
use App\Exceptions\ManageEntryException; use App\Exceptions\ManageEntryException;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
@ -139,7 +140,7 @@ class EntryController extends Controller
return view('admin.entries.edit', compact('entry', 'students', 'auditions', 'scores')); 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')) { if ($entry->audition->hasFlag('seats_published')) {
return to_route('admin.entries.index')->with('error', 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_seating'] = $request->get('for_seating') ? 1 : 0;
$validData['for_advancement'] = $request->get('for_advancement') ? 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')) { if (! auditionSetting('advanceTo')) {
$validData['for_seating'] = 1; $validData['for_seating'] = 1;
} }
try {
$updater($entry, $validData);
} catch (ManageEntryException $e) {
return redirect()->route('admin.entries.index')->with('error', $e->getMessage());
}
$entry->update([ // $entry->update([
'audition_id' => $validData['audition_id'], // 'audition_id' => $validData['audition_id'],
'for_seating' => $validData['for_seating'], // 'for_seating' => $validData['for_seating'],
'for_advancement' => $validData['for_advancement'], // 'for_advancement' => $validData['for_advancement'],
]); // ]);
return to_route('admin.entries.index')->with('success', 'Entry updated successfully'); 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 () { it('allows an admin to update an entry', function () {
// Arrange // Arrange
$newAudition = Audition::factory()->create(); $newAudition = Audition::factory()->create(['minimum_grade' => 1, 'maximum_grade' => 20]);
actAsAdmin(); actAsAdmin();
// Act & Assert // Act & Assert
/** @noinspection PhpUnhandledExceptionInspection */ /** @noinspection PhpUnhandledExceptionInspection */
patch(route('admin.entries.update', $this->entry), ['audition_id' => $newAudition->id]) patch(route('admin.entries.update', $this->entry), ['audition_id' => $newAudition->id])
->assertSessionHasNoErrors() ->assertSessionHasNoErrors()
->assertSessionMissing('error')
->assertSessionHas('success', 'Entry updated successfully') ->assertSessionHas('success', 'Entry updated successfully')
->assertRedirect(route('admin.entries.index')); ->assertRedirect(route('admin.entries.index'));
$this->entry->refresh(); $this->entry->refresh();
@ -221,7 +222,7 @@ it('displays scores', function () {
$response->assertSee($subscore->name); $response->assertSee($subscore->name);
} }
}); });
it('has a link to delete scores', function() { it('has a link to delete scores', function () {
// Arrange // Arrange
$sg = ScoringGuide::factory()->create(); $sg = ScoringGuide::factory()->create();
SubscoreDefinition::factory()->count(5)->create(['scoring_guide_id' => $sg->id]); 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(); $scoreSheet = ScoreSheet::where('entry_id', $entry->id)->first();
actAsAdmin(); actAsAdmin();
$response = get(route('admin.entries.edit', $entry)) $response = get(route('admin.entries.edit', $entry))
->assertSee(route('scores.destroy', ['score'=>$scoreSheet])); ->assertSee(route('scores.destroy', ['score' => $scoreSheet]));
}); });
// Delete tests // Delete tests