From e4b1c238f3646909059f15a32f092d5866828ef9 Mon Sep 17 00:00:00 2001 From: Nabeel S Date: Tue, 9 Jun 2020 06:10:40 -0700 Subject: [PATCH] Add ACARS update event #755 (#756) --- app/Events/AcarsUpdate.php | 21 ++++++++++++++++ app/Http/Controllers/Api/AcarsController.php | 4 +++ .../Listeners/AcarsUpdateListener.php | 25 +++++++++++++++++++ .../Listeners/PirepAcceptedEventListener.php | 4 ++- .../Providers/EventServiceProvider.php | 6 ++--- 5 files changed, 56 insertions(+), 4 deletions(-) create mode 100644 app/Events/AcarsUpdate.php create mode 100644 modules/Vacentral/Listeners/AcarsUpdateListener.php diff --git a/app/Events/AcarsUpdate.php b/app/Events/AcarsUpdate.php new file mode 100644 index 00000000..4b4d7711 --- /dev/null +++ b/app/Events/AcarsUpdate.php @@ -0,0 +1,21 @@ +pirep = $pirep; + $this->acars = $acars; + } +} diff --git a/app/Http/Controllers/Api/AcarsController.php b/app/Http/Controllers/Api/AcarsController.php index d45bb62f..042482a1 100644 --- a/app/Http/Controllers/Api/AcarsController.php +++ b/app/Http/Controllers/Api/AcarsController.php @@ -3,6 +3,7 @@ namespace App\Http\Controllers\Api; use App\Contracts\Controller; +use App\Events\AcarsUpdate; use App\Exceptions\PirepCancelled; use App\Http\Requests\Acars\EventRequest; use App\Http\Requests\Acars\LogRequest; @@ -198,6 +199,9 @@ class AcarsController extends Controller $pirep->save(); + // Post a new update for this ACARS position + event(new AcarsUpdate($pirep, $pirep->position)); + return $this->message($count.' positions added', $count); } diff --git a/modules/Vacentral/Listeners/AcarsUpdateListener.php b/modules/Vacentral/Listeners/AcarsUpdateListener.php new file mode 100644 index 00000000..78ce4580 --- /dev/null +++ b/modules/Vacentral/Listeners/AcarsUpdateListener.php @@ -0,0 +1,25 @@ +vacentral = $vacentral; + } + + /** + * @param AcarsUpdate $event + */ + public function handle(AcarsUpdate $event) + { + Log::info('Received acars update event', [$event]); + } +} diff --git a/modules/Vacentral/Listeners/PirepAcceptedEventListener.php b/modules/Vacentral/Listeners/PirepAcceptedEventListener.php index f1c388cc..429661a3 100644 --- a/modules/Vacentral/Listeners/PirepAcceptedEventListener.php +++ b/modules/Vacentral/Listeners/PirepAcceptedEventListener.php @@ -3,12 +3,14 @@ namespace Modules\Vacentral\Listeners; use App\Events\PirepAccepted; -use Log; +use Illuminate\Support\Facades\Log; class PirepAcceptedEventListener { /** * Handle the event. + * + * @param PirepAccepted $pirep */ public function handle(PirepAccepted $pirep) { diff --git a/modules/Vacentral/Providers/EventServiceProvider.php b/modules/Vacentral/Providers/EventServiceProvider.php index 73b52458..847f3589 100644 --- a/modules/Vacentral/Providers/EventServiceProvider.php +++ b/modules/Vacentral/Providers/EventServiceProvider.php @@ -2,16 +2,16 @@ namespace Modules\Vacentral\Providers; +use App\Events\AcarsUpdate; use App\Events\PirepAccepted; use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; +use Modules\Vacentral\Listeners\AcarsUpdateListener; use Modules\Vacentral\Listeners\PirepAcceptedEventListener; class EventServiceProvider extends ServiceProvider { - /** - * The event listener mappings for the application. - */ protected $listen = [ + AcarsUpdate::class => [AcarsUpdateListener::class], PirepAccepted::class => [PirepAcceptedEventListener::class], ]; }