From 3cf7bb8ca5cb9f06b2273710fbead2948955053a Mon Sep 17 00:00:00 2001 From: Nabeel Shahzad Date: Fri, 9 Aug 2019 22:44:04 -0400 Subject: [PATCH] Add missing expiry time for PIREP API --- app/Console/Commands/DevCommands.php | 10 ++++++++++ app/Http/Controllers/Api/PirepController.php | 16 ++++++---------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/app/Console/Commands/DevCommands.php b/app/Console/Commands/DevCommands.php index 201a108ef..fe2cf6990 100644 --- a/app/Console/Commands/DevCommands.php +++ b/app/Console/Commands/DevCommands.php @@ -7,6 +7,7 @@ use App\Models\Airline; use App\Models\Pirep; use App\Models\User; +use App\Repositories\AcarsRepository; use App\Services\AirportService; use App\Services\AwardService; use App\Services\DatabaseService; @@ -55,6 +56,7 @@ public function handle() 'compile-assets' => 'compileAssets', 'db-attrs' => 'dbAttrs', 'list-awards' => 'listAwardClasses', + 'live-flights' => 'liveFlights', 'manual-insert' => 'manualInsert', 'metar' => 'getMetar', 'reset-install' => 'resetInstall', @@ -278,4 +280,12 @@ protected function resetInstall(): void $this->info('Done!'); } + + public function liveFlights(): void + { + $acarsRepo = app(AcarsRepository::class); + $flights = $acarsRepo->getPositions(setting('acars.live_time'))->toArray(); + + dd($flights); + } } diff --git a/app/Http/Controllers/Api/PirepController.php b/app/Http/Controllers/Api/PirepController.php index 535621ac3..9a655b80d 100644 --- a/app/Http/Controllers/Api/PirepController.php +++ b/app/Http/Controllers/Api/PirepController.php @@ -166,17 +166,13 @@ protected function updateFares($pirep, Request $request) */ public function index() { - $active = []; - $pireps = $this->acarsRepo->getPositions(); - foreach ($pireps as $pirep) { - if (!$pirep->position) { - continue; - } - - $active[] = $pirep; - } + $pireps = $this->acarsRepo + ->getPositions(setting('acars.live_time')) + ->filter(function ($pirep) { + return $pirep->position !== null; + }); - return PirepResource::collection(collect($active)); + return PirepResource::collection($pireps); } /**