Cache and event updates.
This commit is contained in:
parent
008cf0e7b0
commit
ff85fd1c86
|
|
@ -10,7 +10,7 @@ use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
|||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class ScoringGuideChange
|
||||
class AuditionChange
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
<?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'),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Events\AuditionChange;
|
||||
use App\Events\RoomJudgeChange;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Audition;
|
||||
use App\Models\Event;
|
||||
|
|
@ -31,6 +33,7 @@ class AuditionController extends Controller
|
|||
{
|
||||
if(! Auth::user()->is_admin) abort(403);
|
||||
$events = Event::orderBy('name')->get();
|
||||
|
||||
return view('admin.auditions.create',['events'=> $events]);
|
||||
}
|
||||
|
||||
|
|
@ -57,7 +60,7 @@ class AuditionController extends Controller
|
|||
'minimum_grade' => $validData['minimum_grade'],
|
||||
'maximum_grade' => $validData['maximum_grade'],
|
||||
]);
|
||||
|
||||
AuditionChange::dispatch();
|
||||
return redirect('/admin/auditions');
|
||||
}
|
||||
|
||||
|
|
@ -91,7 +94,7 @@ class AuditionController extends Controller
|
|||
'minimum_grade' => $validData['minimum_grade'],
|
||||
'maximum_grade' => $validData['maximum_grade'],
|
||||
]);
|
||||
|
||||
AuditionChange::dispatch();
|
||||
return redirect('/admin/auditions');
|
||||
}
|
||||
|
||||
|
|
@ -103,6 +106,7 @@ class AuditionController extends Controller
|
|||
$audition = Audition::find($id);
|
||||
$audition->update(['score_order' => $index]);
|
||||
}
|
||||
AuditionChange::dispatch();
|
||||
return response()->json(['status' => 'success']);
|
||||
}
|
||||
|
||||
|
|
@ -117,7 +121,7 @@ class AuditionController extends Controller
|
|||
'order_in_room' => $audition['room_order']
|
||||
]);
|
||||
}
|
||||
|
||||
AuditionChange::dispatch();
|
||||
return response()->json(['status' => 'success']);
|
||||
}
|
||||
|
||||
|
|
@ -133,7 +137,7 @@ class AuditionController extends Controller
|
|||
|
||||
return response()->json(['success' => true]);
|
||||
}
|
||||
|
||||
AuditionChange::dispatch();
|
||||
return response()->json(['success' => false], 404);
|
||||
}
|
||||
|
||||
|
|
@ -145,6 +149,7 @@ class AuditionController extends Controller
|
|||
return redirect()->route('adminAuditionIndex')->with('error', 'Cannot delete an audition with entries.');
|
||||
}
|
||||
$audition->delete();
|
||||
AuditionChange::dispatch();
|
||||
return redirect('/admin/auditions');
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Events\RoomJudgeChange;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Audition;
|
||||
use App\Models\Room;
|
||||
|
|
@ -47,11 +48,11 @@ class RoomController extends Controller
|
|||
} else {
|
||||
return redirect('/admin/rooms/judging_assignments')->with('error', 'Invalid request method.');
|
||||
}
|
||||
|
||||
RoomJudgeChange::dispatch();
|
||||
return redirect('/admin/rooms/judging_assignments')->with('success',$message);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// TODO need to be able to add new rooms. Dispatch RoomJudgeChange when we do.
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Events\ScoringGuideChange;
|
||||
use App\Events\AuditionChange;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\ScoringGuide;
|
||||
use App\Models\SubscoreDefinition;
|
||||
|
|
@ -38,7 +38,7 @@ class ScoringGuideController extends Controller
|
|||
'name' => request('name')
|
||||
]);
|
||||
|
||||
ScoringGuideChange::dispatch();
|
||||
AuditionChange::dispatch();
|
||||
|
||||
return redirect('/admin/scoring');
|
||||
}
|
||||
|
|
@ -65,7 +65,7 @@ class ScoringGuideController extends Controller
|
|||
$guide->update([
|
||||
'name' => request('name')
|
||||
]);
|
||||
ScoringGuideChange::dispatch();
|
||||
AuditionChange::dispatch();
|
||||
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,
|
||||
]);
|
||||
ScoringGuideChange::dispatch();
|
||||
AuditionChange::dispatch();
|
||||
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]);
|
||||
}
|
||||
ScoringGuideChange::dispatch();
|
||||
AuditionChange::dispatch();
|
||||
return response()->json(['status'=>'success']);
|
||||
|
||||
}
|
||||
|
|
@ -122,7 +122,7 @@ class ScoringGuideController extends Controller
|
|||
$subscore = SubscoreDefinition::find($id);
|
||||
$subscore->update(['tiebreak_order' => $index]);
|
||||
}
|
||||
ScoringGuideChange::dispatch();
|
||||
AuditionChange::dispatch();
|
||||
return response()->json(['status'=>'success']);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Events\RoomJudgeChange;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Mail\NewUserPassword;
|
||||
use App\Models\School;
|
||||
|
|
@ -56,7 +57,7 @@ class UserController extends Controller
|
|||
'judging_preference' => request('judging_preference'),
|
||||
'school_id' => request('school_id')
|
||||
]);
|
||||
|
||||
RoomJudgeChange::dispatch();
|
||||
return redirect('/admin/users');
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Services\ScoringGuideCacheService;
|
||||
use App\Services\AuditionCacheService;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
|
||||
|
|
@ -10,14 +10,14 @@ class TestController extends Controller
|
|||
{
|
||||
protected $scoringGuideCacheService;
|
||||
|
||||
public function __construct(ScoringGuideCacheService $scoringGuideCacheService)
|
||||
public function __construct(AuditionCacheService $scoringGuideCacheService)
|
||||
{
|
||||
$this->scoringGuideCacheService = $scoringGuideCacheService;
|
||||
}
|
||||
|
||||
public function flashTest(Request $request)
|
||||
{
|
||||
$sg = $this->scoringGuideCacheService->getScoringGuides();
|
||||
$sg = $this->scoringGuideCacheService->getAuditions();
|
||||
|
||||
return view('test', compact('sg'));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -81,3 +81,6 @@ class UserController extends Controller
|
|||
return redirect('/my_school');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//TODO allow users to modify their profile information. RoomJudgeChange::dispatch(); when they do
|
||||
|
|
|
|||
|
|
@ -2,18 +2,18 @@
|
|||
|
||||
namespace App\Listeners;
|
||||
|
||||
use App\Events\ScoringGuideChange;
|
||||
use App\Services\ScoringGuideCacheService;
|
||||
use App\Events\AuditionChange;
|
||||
use App\Services\AuditionCacheService;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
|
||||
class RefreshScoringGuideCache
|
||||
class RefreshAuditionCache
|
||||
{
|
||||
protected $cacheService;
|
||||
/**
|
||||
* Create the event listener.
|
||||
*/
|
||||
public function __construct(ScoringGuideCacheService $cacheService)
|
||||
public function __construct(AuditionCacheService $cacheService)
|
||||
{
|
||||
$this->cacheService = $cacheService;
|
||||
}
|
||||
|
|
@ -21,7 +21,7 @@ class RefreshScoringGuideCache
|
|||
/**
|
||||
* Handle the event.
|
||||
*/
|
||||
public function handle(ScoringGuideChange $event): void
|
||||
public function handle(AuditionChange $event): void
|
||||
{
|
||||
$this->cacheService->refreshCache();
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
<?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();
|
||||
}
|
||||
}
|
||||
|
|
@ -2,8 +2,8 @@
|
|||
|
||||
namespace App\Providers;
|
||||
|
||||
use App\Events\ScoringGuideChange;
|
||||
use App\Listeners\RefreshScoringGuideCache;
|
||||
use App\Events\AuditionChange;
|
||||
use App\Listeners\RefreshAuditionCache;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
|
|
@ -23,8 +23,8 @@ class AppServiceProvider extends ServiceProvider
|
|||
public function boot(): void
|
||||
{
|
||||
Event::listen(
|
||||
ScoringGuideChange::class,
|
||||
RefreshScoringGuideCache::class
|
||||
AuditionChange::class,
|
||||
RefreshAuditionCache::class
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,12 +2,13 @@
|
|||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\Audition;
|
||||
use App\Models\ScoringGuide;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class ScoringGuideCacheService
|
||||
class AuditionCacheService
|
||||
{
|
||||
protected $cacheKey = 'scoring_guides';
|
||||
protected $cacheKey = 'auditions';
|
||||
/**
|
||||
* Create a new class instance.
|
||||
*/
|
||||
|
|
@ -16,16 +17,16 @@ class ScoringGuideCacheService
|
|||
//
|
||||
}
|
||||
|
||||
public function getScoringGuides()
|
||||
public function getAuditions()
|
||||
{
|
||||
return Cache::rememberForever($this->cacheKey, function () {
|
||||
return ScoringGuide::with('subscores')->get();
|
||||
return Audition::with(['scoringGuide.subscores'])->get();
|
||||
});
|
||||
}
|
||||
|
||||
public function refreshCache()
|
||||
{
|
||||
Cache::forget($this->cacheKey);
|
||||
$this->getScoringGuides();
|
||||
$this->getAuditions();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
<?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();
|
||||
}
|
||||
}
|
||||
|
|
@ -4,7 +4,7 @@
|
|||
use App\Models\SchoolEmailDomain;
|
||||
use App\Models\ScoreSheet;
|
||||
use App\Models\ScoringGuide;
|
||||
use App\Models\User;use App\Services\ScoringGuideCacheService;use App\Settings;
|
||||
use App\Models\User;use App\Services\AuditionCacheService;use App\Settings;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
|
|
|
|||
Loading…
Reference in New Issue