diff --git a/app/Events/AuditionChange.php b/app/Events/AuditionChange.php index 0f24699..9e7f1e4 100644 --- a/app/Events/AuditionChange.php +++ b/app/Events/AuditionChange.php @@ -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; } /** diff --git a/app/Events/RoomJudgeChange.php b/app/Events/RoomJudgeChange.php deleted file mode 100644 index 5d9e8c6..0000000 --- a/app/Events/RoomJudgeChange.php +++ /dev/null @@ -1,36 +0,0 @@ - - */ - public function broadcastOn(): array - { - return [ - new PrivateChannel('channel-name'), - ]; - } -} diff --git a/app/Http/Controllers/Admin/AuditionController.php b/app/Http/Controllers/Admin/AuditionController.php index fcf00ab..d34d09e 100644 --- a/app/Http/Controllers/Admin/AuditionController.php +++ b/app/Http/Controllers/Admin/AuditionController.php @@ -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'); } diff --git a/app/Http/Controllers/Admin/RoomController.php b/app/Http/Controllers/Admin/RoomController.php index 117892a..b05852d 100644 --- a/app/Http/Controllers/Admin/RoomController.php +++ b/app/Http/Controllers/Admin/RoomController.php @@ -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); } diff --git a/app/Http/Controllers/Admin/ScoringGuideController.php b/app/Http/Controllers/Admin/ScoringGuideController.php index 4838028..01240f7 100644 --- a/app/Http/Controllers/Admin/ScoringGuideController.php +++ b/app/Http/Controllers/Admin/ScoringGuideController.php @@ -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']); } diff --git a/app/Http/Controllers/Admin/UserController.php b/app/Http/Controllers/Admin/UserController.php index ad1beb9..0c96bdb 100644 --- a/app/Http/Controllers/Admin/UserController.php +++ b/app/Http/Controllers/Admin/UserController.php @@ -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'); } diff --git a/app/Http/Controllers/EntryController.php b/app/Http/Controllers/EntryController.php index 744c690..2aa6201 100644 --- a/app/Http/Controllers/EntryController.php +++ b/app/Http/Controllers/EntryController.php @@ -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.'); } diff --git a/app/Listeners/RefreshAuditionCache.php b/app/Listeners/RefreshAuditionCache.php index 6e45277..f6ae8f3 100644 --- a/app/Listeners/RefreshAuditionCache.php +++ b/app/Listeners/RefreshAuditionCache.php @@ -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(); + } } } diff --git a/app/Listeners/RefreshRoomJudgeCache.php b/app/Listeners/RefreshRoomJudgeCache.php deleted file mode 100644 index 08294c1..0000000 --- a/app/Listeners/RefreshRoomJudgeCache.php +++ /dev/null @@ -1,30 +0,0 @@ -cacheService = $cacheService; - } - - /** - * Handle the event. - */ - public function handle(RoomJudgeChange $event): void - { - $this->cacheService->refreshCache(); - } -} diff --git a/app/Services/AuditionCacheService.php b/app/Services/AuditionCacheService.php index c78058f..f277f28 100644 --- a/app/Services/AuditionCacheService.php +++ b/app/Services/AuditionCacheService.php @@ -39,4 +39,9 @@ class AuditionCacheService Cache::forget($this->cacheKey); $this->getAuditions(); } + + public function clearCache() + { + Cache::forget($this->cacheKey); + } } diff --git a/app/Services/RoomAndJudgeCacheService.php b/app/Services/RoomAndJudgeCacheService.php deleted file mode 100644 index 942cd5b..0000000 --- a/app/Services/RoomAndJudgeCacheService.php +++ /dev/null @@ -1,33 +0,0 @@ -cacheKey, function () { - return Room::with(['judges'])->get(); - }); - } - - public function refreshCache() - { - Cache::forget($this->cacheKey); - $this->getAuditions(); - } -}