Remove RoomJudge service

This commit is contained in:
Matt Young 2024-06-15 16:43:48 -05:00
parent 51e59256ef
commit 973dcd7844
11 changed files with 34 additions and 120 deletions

View File

@ -13,13 +13,13 @@ use Illuminate\Queue\SerializesModels;
class AuditionChange
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public bool $refreshCache;
/**
* Create a new event instance.
*/
public function __construct()
public function __construct(bool $refreshCache = true)
{
//
$this->refreshCache = $refreshCache;
}
/**

View File

@ -1,36 +0,0 @@
<?php
namespace App\Events;
use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
class RoomJudgeChange
{
use Dispatchable, InteractsWithSockets, SerializesModels;
/**
* Create a new event instance.
*/
public function __construct()
{
//
}
/**
* Get the channels the event should broadcast on.
*
* @return array<int, \Illuminate\Broadcasting\Channel>
*/
public function broadcastOn(): array
{
return [
new PrivateChannel('channel-name'),
];
}
}

View File

@ -60,7 +60,7 @@ class AuditionController extends Controller
'minimum_grade' => $validData['minimum_grade'],
'maximum_grade' => $validData['maximum_grade'],
]);
AuditionChange::dispatch();
AuditionChange::dispatch(false);
return redirect('/admin/auditions');
}
@ -94,7 +94,7 @@ class AuditionController extends Controller
'minimum_grade' => $validData['minimum_grade'],
'maximum_grade' => $validData['maximum_grade'],
]);
AuditionChange::dispatch();
AuditionChange::dispatch(false);
return redirect('/admin/auditions');
}
@ -106,7 +106,7 @@ class AuditionController extends Controller
$audition = Audition::find($id);
$audition->update(['score_order' => $index]);
}
AuditionChange::dispatch();
AuditionChange::dispatch(false);
return response()->json(['status' => 'success']);
}
@ -121,7 +121,7 @@ class AuditionController extends Controller
'order_in_room' => $audition['room_order']
]);
}
AuditionChange::dispatch();
AuditionChange::dispatch(false);
return response()->json(['status' => 'success']);
}
@ -137,7 +137,7 @@ class AuditionController extends Controller
return response()->json(['success' => true]);
}
AuditionChange::dispatch();
AuditionChange::dispatch(false);
return response()->json(['success' => false], 404);
}
@ -149,7 +149,7 @@ class AuditionController extends Controller
return redirect()->route('adminAuditionIndex')->with('error', 'Cannot delete an audition with entries.');
}
$audition->delete();
AuditionChange::dispatch();
AuditionChange::dispatch(false);
return redirect('/admin/auditions');
}

View File

@ -2,6 +2,7 @@
namespace App\Http\Controllers\Admin;
use App\Events\AuditionChange;
use App\Events\RoomJudgeChange;
use App\Http\Controllers\Controller;
use App\Models\Audition;
@ -21,7 +22,7 @@ class RoomController extends Controller
return view('admin.rooms.index', ['rooms' => $rooms]);
}
public function judgingAssignment()
public function judgingAssignment() // Show form for assigning judges
{
$usersWithoutRooms = User::doesntHave('rooms')->orderBy('last_name')->orderBy('first_name')->get();
$usersWithRooms = User::has('rooms')->orderBy('last_name')->orderBy('first_name')->get();
@ -48,7 +49,7 @@ class RoomController extends Controller
} else {
return redirect('/admin/rooms/judging_assignments')->with('error', 'Invalid request method.');
}
RoomJudgeChange::dispatch();
AuditionChange::dispatch(false);
return redirect('/admin/rooms/judging_assignments')->with('success',$message);
}

View File

@ -38,7 +38,7 @@ class ScoringGuideController extends Controller
'name' => request('name')
]);
AuditionChange::dispatch();
AuditionChange::dispatch(false);
return redirect('/admin/scoring');
}
@ -65,7 +65,7 @@ class ScoringGuideController extends Controller
$guide->update([
'name' => request('name')
]);
AuditionChange::dispatch();
AuditionChange::dispatch(false);
return redirect('/admin/scoring/guides/' . $guide->id . '/edit' )->with('success','Scoring guide updated');
}
@ -97,7 +97,7 @@ class ScoringGuideController extends Controller
'for_seating' => $for_seating,
'for_advance' => $for_advance,
]);
AuditionChange::dispatch();
AuditionChange::dispatch(false);
return redirect('/admin/scoring/guides/' . $guide->id . '/edit' )->with('success','Subscore added');
}
@ -109,7 +109,7 @@ class ScoringGuideController extends Controller
$subscore = SubscoreDefinition::find($id);
$subscore->update(['display_order' => $index]);
}
AuditionChange::dispatch();
AuditionChange::dispatch(false);
return response()->json(['status'=>'success']);
}
@ -122,7 +122,7 @@ class ScoringGuideController extends Controller
$subscore = SubscoreDefinition::find($id);
$subscore->update(['tiebreak_order' => $index]);
}
AuditionChange::dispatch();
AuditionChange::dispatch(false);
return response()->json(['status'=>'success']);
}

View File

@ -2,6 +2,7 @@
namespace App\Http\Controllers\Admin;
use App\Events\AuditionChange;
use App\Events\RoomJudgeChange;
use App\Http\Controllers\Controller;
use App\Mail\NewUserPassword;
@ -57,7 +58,7 @@ class UserController extends Controller
'judging_preference' => request('judging_preference'),
'school_id' => request('school_id')
]);
RoomJudgeChange::dispatch();
AuditionChange::dispatch(false);
return redirect('/admin/users');
}

View File

@ -2,6 +2,7 @@
namespace App\Http\Controllers;
use App\Events\AuditionChange;
use App\Models\Audition;
use App\Models\Entry;
use App\Models\School;
@ -35,7 +36,7 @@ class EntryController extends Controller
'student_id' => request('student_id'),
'audition_id' => request('audition_id')
]);
AuditionChange::dispatch();
return redirect('/entries');
}
@ -43,6 +44,7 @@ class EntryController extends Controller
{
if ($request->user()->cannot('delete', $entry)) abort(403);
$entry->delete();
AuditionChange::dispatch();
return redirect('/entries')->with('success','The ' . $entry->audition->name . 'entry for ' . $entry->student->full_name(). 'has been deleted.');
}

View File

@ -9,13 +9,13 @@ use Illuminate\Queue\InteractsWithQueue;
class RefreshAuditionCache
{
protected $cacheService;
protected $auditionCacheService;
/**
* Create the event listener.
*/
public function __construct(AuditionCacheService $cacheService)
{
$this->cacheService = $cacheService;
$this->auditionCacheService = $cacheService;
}
/**
@ -23,7 +23,11 @@ class RefreshAuditionCache
*/
public function handle(AuditionChange $event): void
{
$this->cacheService->refreshCache();
if ($event->refreshCache) {
$this->auditionCacheService->refreshCache();
} else {
$this->auditionCacheService->clearCache();
}
}
}

View File

@ -1,30 +0,0 @@
<?php
namespace App\Listeners;
use App\Events\RoomJudgeChange;
use App\Services\AuditionCacheService;
use App\Services\RoomAndJudgeCacheService;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
class RefreshRoomJudgeCache
{
protected $cacheService;
/**
* Create the event listener.
*/
public function __construct(RoomAndJudgeCacheService $cacheService)
{
$this->cacheService = $cacheService;
}
/**
* Handle the event.
*/
public function handle(RoomJudgeChange $event): void
{
$this->cacheService->refreshCache();
}
}

View File

@ -39,4 +39,9 @@ class AuditionCacheService
Cache::forget($this->cacheKey);
$this->getAuditions();
}
public function clearCache()
{
Cache::forget($this->cacheKey);
}
}

View File

@ -1,33 +0,0 @@
<?php
namespace App\Services;
use App\Models\Audition;
use App\Models\Room;
use App\Models\ScoringGuide;
use Illuminate\Support\Facades\Cache;
class RoomAndJudgeCacheService
{
protected $cacheKey = 'roomJudge';
/**
* Create a new class instance.
*/
public function __construct()
{
//
}
public function getAuditions()
{
return Cache::rememberForever($this->cacheKey, function () {
return Room::with(['judges'])->get();
});
}
public function refreshCache()
{
Cache::forget($this->cacheKey);
$this->getAuditions();
}
}