diff --git a/app/Http/Controllers/LogoController.php b/app/Http/Controllers/LogoController.php new file mode 100644 index 0000000..646b763 --- /dev/null +++ b/app/Http/Controllers/LogoController.php @@ -0,0 +1,41 @@ +logo ?? 'blank.png'; + $path = 'images/logos/tail/' . $logoFile; + if (!Storage::disk('local')->exists($path)) { + $path = 'images/logos/tail/blank.png'; + } + + return response()->file(Storage::disk('local')->path($path), [ + 'Content-Type' => 'image/png', + ]); + } + + public function getLogoByIATACode(string $code) + { + $airline = Airline::where('IATA_code', strtoupper($code))->first(); + return $this->getAirlineLogo($airline); + } + + public function getLogoByICAOCode(string $code) + { + $airline = Airline::where('ICAO_code', strtoupper($code))->first(); + return $this->getAirlineLogo($airline); + } + + public function getLogoByCode(string $code){ + + return strlen($code) == 2 + ? $this->getLogoByIATACode($code) + : $this->getLogoByICAOCode($code); + } +} diff --git a/app/Models/Airline.php b/app/Models/Airline.php new file mode 100644 index 0000000..8b71ed9 --- /dev/null +++ b/app/Models/Airline.php @@ -0,0 +1,28 @@ + 'boolean', + ]; + + public $timestamps = false; +} diff --git a/config/filesystems.php b/config/filesystems.php index 37d8fca..1a41350 100644 --- a/config/filesystems.php +++ b/config/filesystems.php @@ -47,6 +47,7 @@ return [ 'report' => false, ], + 's3' => [ 'driver' => 's3', 'key' => env('AWS_ACCESS_KEY_ID'), diff --git a/database/migrations/2026_04_01_000544_create_airlines_table.php b/database/migrations/2026_04_01_000544_create_airlines_table.php new file mode 100644 index 0000000..6f8c077 --- /dev/null +++ b/database/migrations/2026_04_01_000544_create_airlines_table.php @@ -0,0 +1,34 @@ +id(); + $table->string('IATA_code', 3)->nullable(); + $table->string('ICAO_code', 4)->nullable(); + $table->string('name', 81)->nullable(); + $table->string('internal_name', 81)->nullable(); + $table->string('country_code', 2)->nullable(); + $table->string('country_name', 36)->nullable(); + $table->boolean('active'); + $table->string('logo', 40)->nullable(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('airlines'); + } +}; diff --git a/database/seeders/AirlinesSeeder.php b/database/seeders/AirlinesSeeder.php new file mode 100644 index 0000000..645596d --- /dev/null +++ b/database/seeders/AirlinesSeeder.php @@ -0,0 +1,51 @@ + 'id', + 'codeIataAirline' => 'IATA_code', + 'codeIcaoAirline' => 'ICAO_code', + 'slug' => 'internal_name', + 'nameAirline' => 'name', + 'codeIso2Country' => 'country_code', + 'nameCountry' => 'country_name', + 'statusAirline' => 'active' + ]; + + while (($row = fgetcsv($file, separator: ';')) !== false) { + $data = array_combine($header, $row); + $filtered = array_intersect_key($data, array_flip($keep)); + + foreach ($renames as $old => $new) { + if (array_key_exists($old, $filtered)) { + $filtered[$new] = $filtered[$old]; + unset($filtered[$old]); + } + } + $filtered['active'] = $filtered['active'] === 'active'; + $filtered['logo'] = $filtered['IATA_code'] ? $filtered['IATA_code'].'.png' : null; + DB::table('airlines')->insert($filtered); + } + + fclose($file); + } +} diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index 6b901f8..e68af39 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -15,11 +15,6 @@ class DatabaseSeeder extends Seeder */ public function run(): void { - // User::factory(10)->create(); - - User::factory()->create([ - 'name' => 'Test User', - 'email' => 'test@example.com', - ]); + $this->call(AirlinesSeeder::class); } } diff --git a/routes/web.php b/routes/web.php index 1b5750c..3b8f015 100644 --- a/routes/web.php +++ b/routes/web.php @@ -1,7 +1,11 @@ json(['message' => 'Welcome to Dredgy\'s Flights API']); }); + +Route::get('airlines/logos/{code}', [LogoController::class, 'getLogoByCode']) + ->where('code', '[A-Za-z0-9]{2,3}');