Cache the api calls to vacentral and make the iata field optional

This commit is contained in:
Nabeel Shahzad 2017-12-07 17:44:05 -06:00
parent ddb8a6f5e9
commit fa4be69774
5 changed files with 16 additions and 15 deletions

1
.gitignore vendored
View File

@ -27,6 +27,7 @@ Homestead.json
tmp/
# intellij files
.idea/composerJson.xml
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/dictionaries

View File

@ -1,12 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ComposerJsonPluginSettings">
<unboundedVersionInspectionSettings>
<excludedPackages>
<pattern pattern="makinacorpus/php-bloom" />
<pattern pattern="nabeel/*" />
</excludedPackages>
</unboundedVersionInspectionSettings>
<customRepositories />
</component>
</project>

View File

@ -6,6 +6,7 @@ use App\Repositories\AirportRepository;
use App\Http\Controllers\AppBaseController;
use App\Http\Resources\Airport as AirportResource;
use Illuminate\Support\Facades\Cache;
use VaCentral\Airport as AirportLookup;
class AirportController extends AppBaseController
@ -25,7 +26,14 @@ class AirportController extends AppBaseController
*/
public function lookup($id)
{
$airport = AirportLookup::get($id);
$airport = Cache::remember(
config('cache.keys.AIRPORT_VACENTRAL_LOOKUP.key') . $id,
config('cache.keys.RANKS_PILOT_LIST.time'),
function () use ($id) {
return AirportLookup::get($id);
}
);
return new AirportResource(collect($airport));
}
}

View File

@ -6,9 +6,13 @@ return [
'prefix' => env('CACHE_PREFIX', ''),
'keys' => [
'AIRPORT_VACENTRAL_LOOKUP' => [
'key' => 'airports:lookup:',
'time' => 1800,
],
'RANKS_PILOT_LIST' => [
'key' => 'ranks:pilot_list',
'time' => 1440,
'time' => 600,
]
],

View File

@ -16,7 +16,7 @@ class CreateAirportsTable extends Migration
Schema::create('airports', function (Blueprint $table) {
// $table->bigIncrements('id');
$table->string('id', 5)->primary();
$table->string('iata', 5);
$table->string('iata', 5)->nullable();
$table->string('icao', 5);
$table->string('name', 100);
$table->string('location', 100)->nullable();