Skip to content

Commit

Permalink
Add ACARS update event #755 (#756)
Browse files Browse the repository at this point in the history
  • Loading branch information
nabeelio authored Jun 9, 2020
1 parent 57e9102 commit e4b1c23
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 4 deletions.
21 changes: 21 additions & 0 deletions app/Events/AcarsUpdate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace App\Events;

use App\Models\Acars;
use App\Models\Pirep;

class AcarsUpdate extends BaseEvent
{
/** @var Pirep */
public $pirep;

/** @var Acars */
public $acars;

public function __construct(Pirep $pirep, Acars $acars)
{
$this->pirep = $pirep;
$this->acars = $acars;
}
}
4 changes: 4 additions & 0 deletions app/Http/Controllers/Api/AcarsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -198,6 +199,9 @@ public function acars_store($id, PositionRequest $request)

$pirep->save();

// Post a new update for this ACARS position
event(new AcarsUpdate($pirep, $pirep->position));

return $this->message($count.' positions added', $count);
}

Expand Down
25 changes: 25 additions & 0 deletions modules/Vacentral/Listeners/AcarsUpdateListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Modules\Vacentral\Listeners;

use App\Events\AcarsUpdate;
use Illuminate\Support\Facades\Log;
use VaCentral\Contracts\IVaCentral;

class AcarsUpdateListener
{
private $vacentral;

public function __construct(IVaCentral $vacentral)
{
$this->vacentral = $vacentral;
}

/**
* @param AcarsUpdate $event
*/
public function handle(AcarsUpdate $event)
{
Log::info('Received acars update event', [$event]);
}
}
4 changes: 3 additions & 1 deletion modules/Vacentral/Listeners/PirepAcceptedEventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
6 changes: 3 additions & 3 deletions modules/Vacentral/Providers/EventServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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],
];
}

0 comments on commit e4b1c23

Please sign in to comment.