Auditionadmin 29 #40
|
|
@ -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']);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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');
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue