Set airport and landing time of aircraft after pirep accept #112

This commit is contained in:
Nabeel Shahzad
2018-01-10 12:39:13 -06:00
parent 2f33c7b6aa
commit dce9723979
5 changed files with 47 additions and 5 deletions

View File

@@ -1,5 +1,7 @@
<?php
use \App\Models\Enums\AircraftState;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
@@ -12,14 +14,17 @@ class CreateAircraftsTable extends Migration
$table->unsignedInteger('subfleet_id');
$table->string('icao', 4)->nullable();
$table->string('airport_id', 5)->nullable();
$table->timestamp('landing_time')->nullable();
$table->string('hex_code', 10)->nullable();
$table->string('name', 50);
$table->string('registration', 10)->nullable();
$table->string('tail_number', 10)->nullable();
$table->boolean('active')->default(true);
$table->unsignedTinyInteger('state')->default(AircraftState::PARKED);
$table->timestamps();
$table->unique('registration');
$table->index('airport_id');
});
}

View File

@@ -0,0 +1,20 @@
<?php
namespace App\Models\Enums;
/**
* Class AircraftState
* @package App\Models\Enums
*/
class AircraftState extends EnumBase
{
const PARKED = 0;
const IN_USE = 1;
const IN_AIR = 2;
public static $labels = [
AircraftState::PARKED => 'On Ground',
AircraftState::IN_USE => 'In Use',
AircraftState::IN_AIR => 'In Air',
];
}

View File

@@ -267,6 +267,11 @@ class PIREPService extends BaseService
Log::info('PIREP ' . $pirep->id . ' state change to ACCEPTED');
# Update the aircraft
$pirep->aircraft->airport_id = $pirep->arr_airport_id;
$pirep->aircraft->landing_time = $pirep->updated_at;
$pirep->aircraft->save();
event(new PirepAccepted($pirep));
return $pirep;