Catch up
This commit is contained in:
parent
df561164be
commit
fb2c5724ec
|
|
@ -5,6 +5,7 @@ namespace App\Http\Controllers\Admin;
|
|||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Audition;
|
||||
use App\Models\Event;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
|
|
@ -21,7 +22,8 @@ class AuditionController extends Controller
|
|||
{
|
||||
public function index()
|
||||
{
|
||||
$auditions = Audition::with(['event'])->withCount('entries')->orderBy('score_order')->orderBy('created_at', 'desc')->get();
|
||||
$auditions = Audition::with(['event'])->withCount('entries')->orderBy('score_order')->orderBy('created_at',
|
||||
'desc')->get();
|
||||
|
||||
return view('admin.auditions.index', ['auditions' => $auditions]);
|
||||
}
|
||||
|
|
@ -48,12 +50,16 @@ class AuditionController extends Controller
|
|||
'entry_fee' => ['required', 'numeric'],
|
||||
'minimum_grade' => ['required', 'integer'],
|
||||
'maximum_grade' => 'required|numeric|gte:minimum_grade',
|
||||
'scoring_guide_id' => 'nullable|exists:scoring_guides,id',
|
||||
], [
|
||||
'maximum_grade.gte' => 'The maximum grade must be greater than the minimum grade.',
|
||||
]);
|
||||
|
||||
$validData['for_seating'] = $request->get('for_seating') ? 1 : 0;
|
||||
$validData['for_advancement'] = $request->get('for_advancement') ? 1 : 0;
|
||||
if (empty($alidData['scoring_guide_id'])) {
|
||||
$validData['scoring_guide_id'] = 0;
|
||||
}
|
||||
|
||||
Audition::create([
|
||||
'event_id' => $validData['event_id'],
|
||||
|
|
@ -64,6 +70,7 @@ class AuditionController extends Controller
|
|||
'maximum_grade' => $validData['maximum_grade'],
|
||||
'for_seating' => $validData['for_seating'],
|
||||
'for_advancement' => $validData['for_advancement'],
|
||||
'scoring_guide_id' => $validData['scoring_guide_id'],
|
||||
]);
|
||||
|
||||
return to_route('admin.auditions.index')->with('success', 'Audition created successfully');
|
||||
|
|
@ -142,6 +149,13 @@ class AuditionController extends Controller
|
|||
return response()->json(['status' => 'success']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the scoring guide for an audition
|
||||
* Used by AJAX call on the scoring guide index page
|
||||
* request should include scoring_guide_id and audition_id
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function scoringGuideUpdate(Request $request)
|
||||
{
|
||||
|
||||
|
|
@ -184,7 +198,8 @@ class AuditionController extends Controller
|
|||
return $audition->has_partial_draw();
|
||||
});
|
||||
|
||||
return view('admin.entries.prepare_draw', compact('nodraw_auditions', 'drawn_auditions', 'partial_draw_auditions'));
|
||||
return view('admin.entries.prepare_draw',
|
||||
compact('nodraw_auditions', 'drawn_auditions', 'partial_draw_auditions'));
|
||||
}
|
||||
|
||||
public function runDraw(Request $request)
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@
|
|||
let auditionId = itemEl.getAttribute('data-id');
|
||||
|
||||
// Make an AJAX request to update the audition_guide_id
|
||||
fetch('/admin/scoring/assign_guide_to_audition', {
|
||||
fetch('{{route('ajax.assignScoringGuideToAudition')}}', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ Route::middleware(['auth', 'verified', CheckIfAdmin::class])->prefix('admin/')->
|
|||
Route::view('/', 'admin.dashboard')->name('admin.dashboard');
|
||||
|
||||
Route::post('/auditions/roomUpdate', [\App\Http\Controllers\Admin\AuditionController::class, 'roomUpdate']); // Endpoint for JS assigning auditions to rooms
|
||||
Route::post('/scoring/assign_guide_to_audition', [\App\Http\Controllers\Admin\AuditionController::class, 'scoringGuideUpdate']); // Endpoint for JS assigning scoring guides to auditions
|
||||
Route::post('/scoring/assign_guide_to_audition', [\App\Http\Controllers\Admin\AuditionController::class, 'scoringGuideUpdate'])->name('ajax.assignScoringGuideToAudition'); // Endpoint for JS assigning scoring guides to auditions
|
||||
|
||||
Route::get('/settings', [\App\Http\Controllers\Admin\AuditionSettings::class, 'index'])->name('audition-settings');
|
||||
Route::post('/settings', [\App\Http\Controllers\Admin\AuditionSettings::class, 'save'])->name('audition-settings-save');
|
||||
|
|
|
|||
|
|
@ -66,6 +66,30 @@ it('allows an administrator to create auditions', function () {
|
|||
->and($checkAudition->for_seating)->toBe(0)
|
||||
->and($checkAudition->for_advancement)->toBe(1);
|
||||
});
|
||||
it('sets scoring_guide_id to 0 if none is set when creating an audition', function () {
|
||||
// Arrange
|
||||
$newEvent = Event::factory()->create();
|
||||
$changes = [
|
||||
'event_id' => $newEvent->id,
|
||||
'name' => 'New Name',
|
||||
'entry_deadline' => '1978-01-01',
|
||||
'entry_fee' => 10000,
|
||||
'minimum_grade' => 3,
|
||||
'maximum_grade' => 8,
|
||||
'for_advancement' => 'on',
|
||||
];
|
||||
actAsAdmin();
|
||||
// Act
|
||||
$response = post(route('admin.auditions.store'), $changes);
|
||||
// Assert
|
||||
/** @noinspection PhpUnhandledExceptionInspection */
|
||||
$response->assertRedirect(route('admin.auditions.index'))
|
||||
->assertSessionHasNoErrors()
|
||||
->assertSessionHas('success', 'Audition created successfully');
|
||||
$checkAudition = Audition::latest()->first();
|
||||
expect($checkAudition->scoring_guide_id)->toBe(0);
|
||||
|
||||
});
|
||||
it('does not allow a normal user or guest to create an audition', function () {
|
||||
// Arrange
|
||||
$precount = Audition::count();
|
||||
|
|
|
|||
|
|
@ -83,3 +83,12 @@ it('only allows an admin to create a new scoring guide', function () {
|
|||
$response->assertRedirect(route('dashboard'))
|
||||
->assertSessionHas('error', 'You are not authorized to perform this action');
|
||||
});
|
||||
it('can assign a scoring guide to an audition', function () {
|
||||
// Arrange
|
||||
$scoringGuide = ScoringGuide::factory()->create();
|
||||
$audition = Audition::factory()->create();
|
||||
// Act & Assert
|
||||
expect($audition->scoring_guide_id)->toBeNull();
|
||||
$response = post(route('ajax.assignScoringGuideToAudition'),
|
||||
['audition_id' => $audition->id, 'new_guide_id' => $scoringGuide->id]);
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue