Send events for Audition cache update from model observers instead of controllers
This commit is contained in:
parent
a6ac8245e5
commit
1bbc322715
|
|
@ -17,7 +17,7 @@ class AuditionChange
|
|||
/**
|
||||
* Create a new event instance.
|
||||
*/
|
||||
public function __construct(bool $refreshCache = true)
|
||||
public function __construct(bool $refreshCache = false)
|
||||
{
|
||||
$this->refreshCache = $refreshCache;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -60,7 +60,6 @@ class AuditionController extends Controller
|
|||
'minimum_grade' => $validData['minimum_grade'],
|
||||
'maximum_grade' => $validData['maximum_grade'],
|
||||
]);
|
||||
AuditionChange::dispatch(false);
|
||||
return redirect('/admin/auditions');
|
||||
}
|
||||
|
||||
|
|
@ -94,7 +93,6 @@ class AuditionController extends Controller
|
|||
'minimum_grade' => $validData['minimum_grade'],
|
||||
'maximum_grade' => $validData['maximum_grade'],
|
||||
]);
|
||||
AuditionChange::dispatch(false);
|
||||
return redirect('/admin/auditions');
|
||||
}
|
||||
|
||||
|
|
@ -106,7 +104,6 @@ class AuditionController extends Controller
|
|||
$audition = Audition::find($id);
|
||||
$audition->update(['score_order' => $index]);
|
||||
}
|
||||
AuditionChange::dispatch(false);
|
||||
return response()->json(['status' => 'success']);
|
||||
}
|
||||
|
||||
|
|
@ -121,7 +118,6 @@ class AuditionController extends Controller
|
|||
'order_in_room' => $audition['room_order']
|
||||
]);
|
||||
}
|
||||
AuditionChange::dispatch(false);
|
||||
return response()->json(['status' => 'success']);
|
||||
}
|
||||
|
||||
|
|
@ -137,7 +133,6 @@ class AuditionController extends Controller
|
|||
|
||||
return response()->json(['success' => true]);
|
||||
}
|
||||
AuditionChange::dispatch(false);
|
||||
return response()->json(['success' => false], 404);
|
||||
}
|
||||
|
||||
|
|
@ -149,7 +144,6 @@ class AuditionController extends Controller
|
|||
return redirect()->route('adminAuditionIndex')->with('error', 'Cannot delete an audition with entries.');
|
||||
}
|
||||
$audition->delete();
|
||||
AuditionChange::dispatch(false);
|
||||
return redirect('/admin/auditions');
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -49,7 +49,6 @@ class RoomController extends Controller
|
|||
} else {
|
||||
return redirect('/admin/rooms/judging_assignments')->with('error', 'Invalid request method.');
|
||||
}
|
||||
AuditionChange::dispatch(false);
|
||||
return redirect('/admin/rooms/judging_assignments')->with('success',$message);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -38,7 +38,6 @@ class ScoringGuideController extends Controller
|
|||
'name' => request('name')
|
||||
]);
|
||||
|
||||
AuditionChange::dispatch(false);
|
||||
|
||||
return redirect('/admin/scoring');
|
||||
}
|
||||
|
|
@ -65,7 +64,6 @@ class ScoringGuideController extends Controller
|
|||
$guide->update([
|
||||
'name' => request('name')
|
||||
]);
|
||||
AuditionChange::dispatch(false);
|
||||
return redirect('/admin/scoring/guides/' . $guide->id . '/edit' )->with('success','Scoring guide updated');
|
||||
}
|
||||
|
||||
|
|
@ -97,7 +95,6 @@ class ScoringGuideController extends Controller
|
|||
'for_seating' => $for_seating,
|
||||
'for_advance' => $for_advance,
|
||||
]);
|
||||
AuditionChange::dispatch(false);
|
||||
return redirect('/admin/scoring/guides/' . $guide->id . '/edit' )->with('success','Subscore added');
|
||||
}
|
||||
|
||||
|
|
@ -109,7 +106,6 @@ class ScoringGuideController extends Controller
|
|||
$subscore = SubscoreDefinition::find($id);
|
||||
$subscore->update(['display_order' => $index]);
|
||||
}
|
||||
AuditionChange::dispatch(false);
|
||||
return response()->json(['status'=>'success']);
|
||||
|
||||
}
|
||||
|
|
@ -122,7 +118,6 @@ class ScoringGuideController extends Controller
|
|||
$subscore = SubscoreDefinition::find($id);
|
||||
$subscore->update(['tiebreak_order' => $index]);
|
||||
}
|
||||
AuditionChange::dispatch(false);
|
||||
return response()->json(['status'=>'success']);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,7 +58,6 @@ class UserController extends Controller
|
|||
'judging_preference' => request('judging_preference'),
|
||||
'school_id' => request('school_id')
|
||||
]);
|
||||
AuditionChange::dispatch(false);
|
||||
return redirect('/admin/users');
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -36,7 +36,6 @@ class EntryController extends Controller
|
|||
'student_id' => request('student_id'),
|
||||
'audition_id' => request('audition_id')
|
||||
]);
|
||||
AuditionChange::dispatch();
|
||||
return redirect('/entries');
|
||||
}
|
||||
|
||||
|
|
@ -44,7 +43,6 @@ 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.');
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
|
||||
namespace App\Observers;
|
||||
|
||||
use App\Events\AuditionChange;
|
||||
use App\Models\Audition;
|
||||
|
||||
class AuditionObserver
|
||||
{
|
||||
/**
|
||||
* Handle the Audition "created" event.
|
||||
*/
|
||||
public function created(Audition $audition): void
|
||||
{
|
||||
AuditionChange::dispatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the Audition "updated" event.
|
||||
*/
|
||||
public function updated(Audition $audition): void
|
||||
{
|
||||
AuditionChange::dispatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the Audition "deleted" event.
|
||||
*/
|
||||
public function deleted(Audition $audition): void
|
||||
{
|
||||
AuditionChange::dispatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the Audition "restored" event.
|
||||
*/
|
||||
public function restored(Audition $audition): void
|
||||
{
|
||||
AuditionChange::dispatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the Audition "force deleted" event.
|
||||
*/
|
||||
public function forceDeleted(Audition $audition): void
|
||||
{
|
||||
AuditionChange::dispatch();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
|
||||
namespace App\Observers;
|
||||
|
||||
use App\Events\AuditionChange;
|
||||
use App\Models\Entry;
|
||||
|
||||
class EntryObserver
|
||||
{
|
||||
/**
|
||||
* Handle the Entry "created" event.
|
||||
*/
|
||||
public function created(Entry $entry): void
|
||||
{
|
||||
AuditionChange::dispatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the Entry "updated" event.
|
||||
*/
|
||||
public function updated(Entry $entry): void
|
||||
{
|
||||
AuditionChange::dispatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the Entry "deleted" event.
|
||||
*/
|
||||
public function deleted(Entry $entry): void
|
||||
{
|
||||
AuditionChange::dispatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the Entry "restored" event.
|
||||
*/
|
||||
public function restored(Entry $entry): void
|
||||
{
|
||||
AuditionChange::dispatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the Entry "force deleted" event.
|
||||
*/
|
||||
public function forceDeleted(Entry $entry): void
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
|
||||
namespace App\Observers;
|
||||
|
||||
use App\Events\AuditionChange;
|
||||
use App\Models\Room;
|
||||
|
||||
class RoomObserver
|
||||
{
|
||||
/**
|
||||
* Handle the Room "created" event.
|
||||
*/
|
||||
public function created(Room $room): void
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the Room "updated" event.
|
||||
*/
|
||||
public function updated(Room $room): void
|
||||
{
|
||||
AuditionChange::dispatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the Room "deleted" event.
|
||||
*/
|
||||
public function deleted(Room $room): void
|
||||
{
|
||||
AuditionChange::dispatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the Room "restored" event.
|
||||
*/
|
||||
public function restored(Room $room): void
|
||||
{
|
||||
AuditionChange::dispatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the Room "force deleted" event.
|
||||
*/
|
||||
public function forceDeleted(Room $room): void
|
||||
{
|
||||
AuditionChange::dispatch();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
|
||||
namespace App\Observers;
|
||||
|
||||
use App\Events\AuditionChange;
|
||||
use App\Models\RoomUser;
|
||||
|
||||
class RoomUserObserver
|
||||
{
|
||||
/**
|
||||
* Handle the RoomUser "created" event.
|
||||
*/
|
||||
public function created(RoomUser $roomUser): void
|
||||
{
|
||||
AuditionChange::dispatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the RoomUser "updated" event.
|
||||
*/
|
||||
public function updated(RoomUser $roomUser): void
|
||||
{
|
||||
AuditionChange::dispatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the RoomUser "deleted" event.
|
||||
*/
|
||||
public function deleted(RoomUser $roomUser): void
|
||||
{
|
||||
AuditionChange::dispatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the RoomUser "restored" event.
|
||||
*/
|
||||
public function restored(RoomUser $roomUser): void
|
||||
{
|
||||
AuditionChange::dispatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the RoomUser "force deleted" event.
|
||||
*/
|
||||
public function forceDeleted(RoomUser $roomUser): void
|
||||
{
|
||||
AuditionChange::dispatch();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
|
||||
namespace App\Observers;
|
||||
|
||||
use App\Events\AuditionChange;
|
||||
use App\Models\School;
|
||||
|
||||
class SchoolObserver
|
||||
{
|
||||
/**
|
||||
* Handle the School "created" event.
|
||||
*/
|
||||
public function created(School $school): void
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the School "updated" event.
|
||||
*/
|
||||
public function updated(School $school): void
|
||||
{
|
||||
AuditionChange::dispatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the School "deleted" event.
|
||||
*/
|
||||
public function deleted(School $school): void
|
||||
{
|
||||
AuditionChange::dispatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the School "restored" event.
|
||||
*/
|
||||
public function restored(School $school): void
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the School "force deleted" event.
|
||||
*/
|
||||
public function forceDeleted(School $school): void
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
|
||||
namespace App\Observers;
|
||||
|
||||
use App\Models\ScoreSheet;
|
||||
|
||||
class ScoreSheetObserver
|
||||
{
|
||||
/**
|
||||
* Handle the ScoreSheet "created" event.
|
||||
*/
|
||||
public function created(ScoreSheet $scoreSheet): void
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the ScoreSheet "updated" event.
|
||||
*/
|
||||
public function updated(ScoreSheet $scoreSheet): void
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the ScoreSheet "deleted" event.
|
||||
*/
|
||||
public function deleted(ScoreSheet $scoreSheet): void
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the ScoreSheet "restored" event.
|
||||
*/
|
||||
public function restored(ScoreSheet $scoreSheet): void
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the ScoreSheet "force deleted" event.
|
||||
*/
|
||||
public function forceDeleted(ScoreSheet $scoreSheet): void
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
|
||||
namespace App\Observers;
|
||||
|
||||
use App\Events\AuditionChange;
|
||||
use App\Models\ScoringGuide;
|
||||
|
||||
class ScoringGuideObserver
|
||||
{
|
||||
/**
|
||||
* Handle the ScoringGuide "created" event.
|
||||
*/
|
||||
public function created(ScoringGuideObserver $scoringGuide): void
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the ScoringGuide "updated" event.
|
||||
*/
|
||||
public function updated(ScoringGuideObserver $scoringGuide): void
|
||||
{
|
||||
AuditionChange::dispatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the ScoringGuide "deleted" event.
|
||||
*/
|
||||
public function deleted(ScoringGuideObserver $scoringGuide): void
|
||||
{
|
||||
AuditionChange::dispatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the ScoringGuide "restored" event.
|
||||
*/
|
||||
public function restored(ScoringGuideObserver $scoringGuide): void
|
||||
{
|
||||
AuditionChange::dispatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the ScoringGuide "force deleted" event.
|
||||
*/
|
||||
public function forceDeleted(ScoringGuideObserver $scoringGuide): void
|
||||
{
|
||||
AuditionChange::dispatch();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
|
||||
namespace App\Observers;
|
||||
|
||||
use App\Events\AuditionChange;
|
||||
use App\Models\Student;
|
||||
|
||||
class StudentObserver
|
||||
{
|
||||
/**
|
||||
* Handle the Student "created" event.
|
||||
*/
|
||||
public function created(Student $student): void
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the Student "updated" event.
|
||||
*/
|
||||
public function updated(Student $student): void
|
||||
{
|
||||
AuditionChange::dispatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the Student "deleted" event.
|
||||
*/
|
||||
public function deleted(Student $student): void
|
||||
{
|
||||
AuditionChange::dispatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the Student "restored" event.
|
||||
*/
|
||||
public function restored(Student $student): void
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the Student "force deleted" event.
|
||||
*/
|
||||
public function forceDeleted(Student $student): void
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
|
||||
namespace App\Observers;
|
||||
|
||||
use App\Events\AuditionChange;
|
||||
use App\Models\SubscoreDefinition;
|
||||
|
||||
class SubscoreDefinitionObserver
|
||||
{
|
||||
/**
|
||||
* Handle the SubscoreDefinition "created" event.
|
||||
*/
|
||||
public function created(SubscoreDefinition $subscoreDefinition): void
|
||||
{
|
||||
AuditionChange::dispatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the SubscoreDefinition "updated" event.
|
||||
*/
|
||||
public function updated(SubscoreDefinition $subscoreDefinition): void
|
||||
{
|
||||
AuditionChange::dispatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the SubscoreDefinition "deleted" event.
|
||||
*/
|
||||
public function deleted(SubscoreDefinition $subscoreDefinition): void
|
||||
{
|
||||
AuditionChange::dispatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the SubscoreDefinition "restored" event.
|
||||
*/
|
||||
public function restored(SubscoreDefinition $subscoreDefinition): void
|
||||
{
|
||||
AuditionChange::dispatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the SubscoreDefinition "force deleted" event.
|
||||
*/
|
||||
public function forceDeleted(SubscoreDefinition $subscoreDefinition): void
|
||||
{
|
||||
AuditionChange::dispatch();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
|
||||
namespace App\Observers;
|
||||
|
||||
use App\Events\AuditionChange;
|
||||
use App\Models\User;
|
||||
|
||||
class UserObserver
|
||||
{
|
||||
/**
|
||||
* Handle the User "created" event.
|
||||
*/
|
||||
public function created(User $user): void
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the User "updated" event.
|
||||
*/
|
||||
public function updated(User $user): void
|
||||
{
|
||||
AuditionChange::dispatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the User "deleted" event.
|
||||
*/
|
||||
public function deleted(User $user): void
|
||||
{
|
||||
AuditionChange::dispatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the User "restored" event.
|
||||
*/
|
||||
public function restored(User $user): void
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the User "force deleted" event.
|
||||
*/
|
||||
public function forceDeleted(User $user): void
|
||||
{
|
||||
AuditionChange::dispatch();
|
||||
}
|
||||
}
|
||||
|
|
@ -4,6 +4,26 @@ namespace App\Providers;
|
|||
|
||||
use App\Events\AuditionChange;
|
||||
use App\Listeners\RefreshAuditionCache;
|
||||
use App\Models\Audition;
|
||||
use App\Models\Entry;
|
||||
use App\Models\Room;
|
||||
use App\Models\RoomUser;
|
||||
use App\Models\School;
|
||||
use App\Models\ScoreSheet;
|
||||
use App\Models\ScoringGuide;
|
||||
use App\Models\Student;
|
||||
use App\Models\SubscoreDefinition;
|
||||
use App\Models\User;
|
||||
use App\Observers\AuditionObserver;
|
||||
use App\Observers\EntryObserver;
|
||||
use App\Observers\RoomObserver;
|
||||
use App\Observers\RoomUserObserver;
|
||||
use App\Observers\SchoolObserver;
|
||||
use App\Observers\ScoreSheetObserver;
|
||||
use App\Observers\ScoringGuideObserver;
|
||||
use App\Observers\StudentObserver;
|
||||
use App\Observers\SubscoreDefinitionObserver;
|
||||
use App\Observers\UserObserver;
|
||||
use App\Services\AuditionCacheService;
|
||||
use App\Services\DoublerService;
|
||||
use App\Services\TabulationService;
|
||||
|
|
@ -35,6 +55,19 @@ class AppServiceProvider extends ServiceProvider
|
|||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
|
||||
Entry::observe(EntryObserver::class);
|
||||
Audition::observe(AuditionObserver::class);
|
||||
Room::observe(RoomObserver::class);
|
||||
RoomUser::observe(RoomUserObserver::class);
|
||||
School::observe(SchoolObserver::class);
|
||||
ScoreSheet::observe(ScoreSheetObserver::class);
|
||||
ScoringGuide::observe(ScoringGuideObservers::class);
|
||||
Student::observe(StudentObserver::class);
|
||||
SubscoreDefinition::observe(SubscoreDefinitionObserver::class);
|
||||
User::observe(UserObserver::class);
|
||||
|
||||
|
||||
Event::listen(
|
||||
AuditionChange::class,
|
||||
RefreshAuditionCache::class
|
||||
|
|
|
|||
Loading…
Reference in New Issue