Discord notifications for PIREP and News events #433 (#1215)

* Discord notifications for events #433

* Style fixes

* Check for blank webhook urls and disable

* Cleanup items after review

* Changes and fixes

* Style fixes

* Don't load env for testing

* Fix status text

* Refactor saving fields/fares so events get the latest data

* Cleanup

* Style fixes
This commit is contained in:
Nabeel S
2021-06-04 10:51:59 -04:00
committed by GitHub
parent 17447c6903
commit 9b2e466b7e
46 changed files with 1249 additions and 456 deletions

View File

@@ -12,6 +12,7 @@ use Carbon\Carbon;
* @property int id
* @property mixed subfleet_id
* @property string airport_id The apt where the aircraft is
* @property string ident
* @property string name
* @property string icao
* @property string registration
@@ -71,6 +72,14 @@ class Aircraft extends Model
'zfw' => 'nullable|numeric',
];
/**
* @return string
*/
public function getIdentAttribute(): string
{
return $this->registration.' ('.$this->icao.')';
}
/**
* See if this aircraft is active
*

View File

@@ -33,7 +33,7 @@ class PirepStatus extends Enum
public const LANDED = 'LAN';
public const ARRIVED = 'ONB'; // On block
public const CANCELLED = 'DX';
public const EMERG_DECENT = 'EMG';
public const EMERG_DESCENT = 'EMG';
protected static $labels = [
self::INITIATED => 'pireps.status.initialized',
@@ -58,6 +58,6 @@ class PirepStatus extends Enum
self::LANDED => 'pireps.status.landed',
self::ARRIVED => 'pireps.status.arrived',
self::CANCELLED => 'pireps.status.cancelled',
self::EMERG_DECENT => 'pireps.status.emerg_decent',
self::EMERG_DESCENT => 'pireps.status.emerg_decent',
];
}

View File

@@ -3,6 +3,7 @@
namespace App\Models;
use App\Contracts\Model;
use Illuminate\Notifications\Notifiable;
/**
* @property int id
@@ -13,6 +14,8 @@ use App\Contracts\Model;
*/
class News extends Model
{
use Notifiable;
public $table = 'news';
protected $fillable = [

View File

@@ -3,6 +3,8 @@
namespace App\Models;
use App\Contracts\Model;
use App\Events\PirepStateChange;
use App\Events\PirepStatusChange;
use App\Models\Enums\AcarsType;
use App\Models\Enums\PirepFieldSource;
use App\Models\Enums\PirepState;
@@ -10,7 +12,9 @@ use App\Models\Traits\HashIdTrait;
use App\Support\Units\Distance;
use App\Support\Units\Fuel;
use Carbon\Carbon;
use Illuminate\Notifications\Notifiable;
use Illuminate\Support\Collection;
use Kleemans\AttributeEvents;
/**
* @property string id
@@ -44,8 +48,8 @@ use Illuminate\Support\Collection;
* @property Flight|null flight
* @property Collection fields
* @property string status
* @property PirepState state
* @property int source
* @property int state
* @property int source
* @property string source_name
* @property Carbon submitted_at
* @property Carbon created_at
@@ -57,7 +61,9 @@ use Illuminate\Support\Collection;
*/
class Pirep extends Model
{
use AttributeEvents;
use HashIdTrait;
use Notifiable;
public $table = 'pireps';
@@ -137,6 +143,14 @@ class Pirep extends Model
'route' => 'nullable',
];
/**
* Auto-dispatch events for lifecycle state changes
*/
protected $dispatchesEvents = [
'status:*' => PirepStatusChange::class,
'state:*' => PirepStateChange::class,
];
/*
* If a PIREP is in these states, then it can't be changed.
*/

View File

@@ -11,6 +11,7 @@ use App\Models\Enums\PirepFieldSource;
* @property string slug
* @property string value
* @property string source
* @property Pirep pirep
*
* @method static updateOrCreate(array $array, array $array1)
*/

View File

@@ -32,6 +32,7 @@ use Laratrust\Traits\LaratrustUserTrait;
* @property Rank rank
* @property Journal journal
* @property int rank_id
* @property string discord_id
* @property int state
* @property bool opt_in
* @property Pirep[] pireps
@@ -66,6 +67,7 @@ class User extends Authenticatable
'pilot_id',
'airline_id',
'rank_id',
'discord_id',
'api_key',
'country',
'home_airport_id',
@@ -89,6 +91,7 @@ class User extends Authenticatable
*/
protected $hidden = [
'api_key',
'discord_id',
'password',
'remember_token',
];