From f29a9cfdc5583dbf092bd63e4add10ac076ded49 Mon Sep 17 00:00:00 2001 From: Nabeel Shahzad Date: Mon, 25 Dec 2017 18:10:24 -0600 Subject: [PATCH] some acars/tables fixes --- app/Console/Commands/AcarsReplay.php | 4 +-- .../2017_12_20_005147_create_acars_tables.php | 2 +- app/Http/Controllers/Api/PirepController.php | 8 +++--- app/Models/Acars.php | 10 +++++++ app/Repositories/SettingRepository.php | 2 ++ tests/AcarsTest.php | 27 +++++++++++++++++-- 6 files changed, 43 insertions(+), 10 deletions(-) diff --git a/app/Console/Commands/AcarsReplay.php b/app/Console/Commands/AcarsReplay.php index a6dd03d8..7313bbb3 100644 --- a/app/Console/Commands/AcarsReplay.php +++ b/app/Console/Commands/AcarsReplay.php @@ -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, diff --git a/app/Database/migrations/2017_12_20_005147_create_acars_tables.php b/app/Database/migrations/2017_12_20_005147_create_acars_tables.php index 566ef259..683a268e 100644 --- a/app/Database/migrations/2017_12_20_005147_create_acars_tables.php +++ b/app/Database/migrations/2017_12_20_005147_create_acars_tables.php @@ -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(); diff --git a/app/Http/Controllers/Api/PirepController.php b/app/Http/Controllers/Api/PirepController.php index ba7ac87f..1c2e4ef9 100644 --- a/app/Http/Controllers/Api/PirepController.php +++ b/app/Http/Controllers/Api/PirepController.php @@ -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); } diff --git a/app/Models/Acars.php b/app/Models/Acars.php index 4b94cb1a..91fdc879 100644 --- a/app/Models/Acars.php +++ b/app/Models/Acars.php @@ -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 */ diff --git a/app/Repositories/SettingRepository.php b/app/Repositories/SettingRepository.php index 19fa9931..9afd1868 100644 --- a/app/Repositories/SettingRepository.php +++ b/app/Repositories/SettingRepository.php @@ -14,6 +14,8 @@ class SettingRepository extends BaseRepository implements CacheableInterface { use CacheableRepository; + public $cacheMinutes = 1; + public function model() { return Setting::class; diff --git a/tests/AcarsTest.php b/tests/AcarsTest.php index 973cad8d..e35c0108 100644 --- a/tests/AcarsTest.php +++ b/tests/AcarsTest.php @@ -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']); + } }