Merge branch 'master' of github.com:nabeelio/phpvms
This commit is contained in:
commit
8aacd844b3
@ -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');
|
||||
});
|
||||
|
||||
}
|
||||
|
20
app/Models/Enums/AircraftState.php
Normal file
20
app/Models/Enums/AircraftState.php
Normal 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',
|
||||
];
|
||||
}
|
@ -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;
|
||||
|
@ -48,8 +48,10 @@ class PIREPTest extends TestCase
|
||||
*/
|
||||
public function testAddPirep()
|
||||
{
|
||||
$user = factory(App\Models\User::class)->create();
|
||||
$route = $this->createNewRoute();
|
||||
$pirep = factory(App\Models\Pirep::class)->create([
|
||||
'user_id' => $user->id,
|
||||
'route' => implode(' ', $route)
|
||||
]);
|
||||
|
||||
@ -73,6 +75,13 @@ class PIREPTest extends TestCase
|
||||
$this->assertEquals($new_flight_time, $pirep->pilot->flight_time);
|
||||
$this->assertEquals($pirep->arr_airport_id, $pirep->pilot->curr_airport_id);
|
||||
|
||||
# Check the location of the current aircraft
|
||||
$this->assertEquals($pirep->aircraft->airport_id, $pirep->arr_airport_id);
|
||||
|
||||
# Also check via API:
|
||||
$this->get('/api/fleet/aircraft/' . $pirep->aircraft_id, [], $user)
|
||||
->assertJson(['airport_id' => $pirep->arr_airport_id]);
|
||||
|
||||
/**
|
||||
* Now go from ACCEPTED to REJECTED
|
||||
*/
|
||||
|
@ -111,14 +111,17 @@ abstract class TestCase extends Illuminate\Foundation\Testing\TestCase
|
||||
* Override the GET call to inject the user API key
|
||||
* @param string $uri
|
||||
* @param array $headers
|
||||
* @param null $user
|
||||
* @return \Illuminate\Foundation\Testing\TestResponse
|
||||
*/
|
||||
public function get($uri, array $headers=[]): \Illuminate\Foundation\Testing\TestResponse
|
||||
public function get($uri, array $headers=[], $user=null): \Illuminate\Foundation\Testing\TestResponse
|
||||
{
|
||||
if(empty($headers)) {
|
||||
if($this->user !== null) {
|
||||
$headers = $this->headers($this->user);
|
||||
}
|
||||
|
||||
if($user !== null) {
|
||||
$headers['x-api-key'] = $user->api_key;
|
||||
}
|
||||
|
||||
return parent::get($uri, $headers);
|
||||
|
Loading…
Reference in New Issue
Block a user