some acars/tables fixes

This commit is contained in:
Nabeel Shahzad 2017-12-25 18:10:24 -06:00
parent 3bd97b4d37
commit f29a9cfdc5
6 changed files with 43 additions and 10 deletions

View File

@ -68,8 +68,8 @@ class AcarsReplay extends Command
'json' => [
'airline_id' => 1,
'aircraft_id' => 1, # TODO: Lookup
'dpt_airport' => $flight->planned_depairport,
'arr_airport' => $flight->planned_destairport,
'dpt_airport_id' => $flight->planned_depairport,
'arr_airport_id' => $flight->planned_destairport,
'altitude' => $flight->planned_altitude,
'planned_flight_time' => $pft,
'route' => $flight->planned_route,

View File

@ -26,7 +26,7 @@ class CreateAcarsTables extends Migration
$table->unsignedInteger('transponder')->nullable();
$table->string('autopilot')->nullable();
$table->decimal('fuel_flow')->nullable();
$table->dateTimeTz('sim_time')->nullable();
$table->string('sim_time')->nullable();
$table->timestamps();

View File

@ -61,8 +61,8 @@ class PirepController extends AppBaseController
$attr['user_id'] = Auth::user()->id;
$attr['airline_id'] = $request->get('airline_id');
$attr['aircraft_id'] = $request->get('aircraft_id');
$attr['dpt_airport_id'] = $request->get('dpt_airport');
$attr['arr_airport_id'] = $request->get('arr_airport');
$attr['dpt_airport_id'] = $request->get('dpt_airport_id');
$attr['arr_airport_id'] = $request->get('arr_airport_id');
$attr['altitude'] = $request->get('altitude');
$attr['route'] = $request->get('route');
$attr['notes'] = $request->get('notes');
@ -89,9 +89,7 @@ class PirepController extends AppBaseController
*/
public function acars_get($id)
{
$pirep = $this->pirepRepo->find($id);
$updates = $this->acarsRepo->forPirep($id);
$updates = $this->acarsRepo->forPirep($this->pirepRepo->find($id));
return new AcarsResource($updates);
}

View File

@ -25,6 +25,16 @@ class Acars extends BaseModel
'sim_time',
];
public $casts = [
'lat' => 'float',
'lon' => 'float',
'heading' => 'integer',
'altitude' => 'integer',
'vs' => 'float',
'gs' => 'float',
'fuel_flow' => 'float',
];
/**
* FKs
*/

View File

@ -14,6 +14,8 @@ class SettingRepository extends BaseRepository implements CacheableInterface
{
use CacheableRepository;
public $cacheMinutes = 1;
public function model()
{
return Setting::class;

View File

@ -35,8 +35,8 @@ class AcarsTest extends TestCase
$pirep = [
'airline_id' => $airline->id,
'aircraft_id' => $aircraft->id,
'dpt_airport' => $airport->icao,
'arr_airport' => $airport->icao,
'dpt_airport_id' => $airport->icao,
'arr_airport_id' => $airport->icao,
'altitude' => 38000,
'planned_flight_time' => 120,
'route' => 'POINTA POINTB',
@ -92,4 +92,27 @@ class AcarsTest extends TestCase
$response = $this->withHeaders($this->apiHeaders())->post($uri, $acars);
$response->assertStatus(404);
}
public function testAcarsIsoDate()
{
$pirep = factory(App\Models\Pirep::class)->make()->toArray();
$uri = '/api/pirep/prefile';
$response = $this->withHeaders($this->apiHeaders())->post($uri, $pirep);
$pirep_id = $response->json()['id'];
$dt = date('c');
$uri = '/api/pirep/' . $pirep_id . '/acars';
$acars = factory(App\Models\Acars::class)->make()->toArray();
$acars['sim_time'] = $dt;
$response = $this->withHeaders($this->apiHeaders())->post($uri, $acars);
$response->assertStatus(201);
$uri = '/api/pirep/' . $pirep_id . '/acars';
$response = $this->withHeaders($this->apiHeaders())->get($uri);
$response->assertStatus(200);
$body = $response->json();
$this->assertEquals($dt, $body[0]['sim_time']);
}
}