Add /api/airlines and /api/airline/{id} #120
This commit is contained in:
4
Procfile
4
Procfile
@@ -1,5 +1,5 @@
|
|||||||
dnsmasq: /usr/local/sbin/dnsmasq --keep-in-foreground
|
dnsmasq: /usr/local/sbin/dnsmasq --keep-in-foreground
|
||||||
php-fpm: /usr/local/sbin/php-fpm --nodaemonize
|
php-fpm: /usr/local/sbin/php-fpm --nodaemonize
|
||||||
nginx: /usr/local/bin/nginx
|
nginx: /usr/local/bin/nginx
|
||||||
mysql: /usr/local/bin/mysqld
|
#mysql: /usr/local/bin/mysqld
|
||||||
mailhog: /usr/local/bin/mailhog
|
#mailhog: /usr/local/bin/mailhog
|
||||||
|
|||||||
41
app/Http/Controllers/Api/AirlineController.php
Normal file
41
app/Http/Controllers/Api/AirlineController.php
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Api;
|
||||||
|
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
|
use App\Repositories\AirlineRepository;
|
||||||
|
use App\Http\Resources\Airline as AirlineResource;
|
||||||
|
|
||||||
|
class AirlineController extends RestController
|
||||||
|
{
|
||||||
|
protected $airlineRepo;
|
||||||
|
|
||||||
|
public function __construct(AirlineRepository $airlineRepo) {
|
||||||
|
$this->airlineRepo = $airlineRepo;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return all the airlines, paginated
|
||||||
|
*/
|
||||||
|
public function index(Request $request)
|
||||||
|
{
|
||||||
|
$airports = $this->airlineRepo
|
||||||
|
->orderBy('name', 'asc')
|
||||||
|
->paginate(50);
|
||||||
|
|
||||||
|
return AirlineResource::collection($airports);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Do a lookup, via vaCentral, for the airport information
|
||||||
|
* @param $id
|
||||||
|
* @return AirlineResource
|
||||||
|
*/
|
||||||
|
public function get($id)
|
||||||
|
{
|
||||||
|
$id = strtoupper($id);
|
||||||
|
AirlineResource::withoutWrapping();
|
||||||
|
return new AirlineResource($this->airlineRepo->find($id));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,6 +7,9 @@ Route::group([], function()
|
|||||||
{
|
{
|
||||||
Route::get('acars', 'AcarsController@index');
|
Route::get('acars', 'AcarsController@index');
|
||||||
|
|
||||||
|
Route::get('airlines', 'AirlineController@index');
|
||||||
|
Route::get('airlines/{id}', 'AirlineController@get');
|
||||||
|
|
||||||
Route::get('airports', 'AirportController@index');
|
Route::get('airports', 'AirportController@index');
|
||||||
Route::get('airports/hubs', 'AirportController@index_hubs');
|
Route::get('airports/hubs', 'AirportController@index_hubs');
|
||||||
Route::get('airports/{id}', 'AirportController@get');
|
Route::get('airports/{id}', 'AirportController@get');
|
||||||
@@ -18,11 +21,13 @@ Route::group([], function()
|
|||||||
Route::get('flights/search', 'FlightController@search');
|
Route::get('flights/search', 'FlightController@search');
|
||||||
Route::get('flights/{id}', 'FlightController@get');
|
Route::get('flights/{id}', 'FlightController@get');
|
||||||
|
|
||||||
|
Route::get('pireps/{id}', 'PirepController@get');
|
||||||
Route::get('pireps/{id}/route', 'PirepController@route_get');
|
Route::get('pireps/{id}/route', 'PirepController@route_get');
|
||||||
Route::get('pireps/{id}/acars/position', 'PirepController@acars_get');
|
Route::get('pireps/{id}/acars/position', 'PirepController@acars_get');
|
||||||
Route::get('pireps/{id}/acars/geojson', 'PirepController@acars_geojson');
|
Route::get('pireps/{id}/acars/geojson', 'PirepController@acars_geojson');
|
||||||
|
|
||||||
Route::get('status', 'StatusController@status');
|
Route::get('status', 'StatusController@status');
|
||||||
|
Route::get('version', 'StatusController@status');
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -30,13 +35,10 @@ Route::group([], function()
|
|||||||
*/
|
*/
|
||||||
Route::group(['middleware' => ['api.auth']], function ()
|
Route::group(['middleware' => ['api.auth']], function ()
|
||||||
{
|
{
|
||||||
Route::get('pireps/{id}', 'PirepController@get');
|
|
||||||
|
|
||||||
Route::post('pireps/prefile', 'PirepController@prefile');
|
Route::post('pireps/prefile', 'PirepController@prefile');
|
||||||
Route::post('pireps/{id}/file', 'PirepController@file');
|
Route::post('pireps/{id}/file', 'PirepController@file');
|
||||||
Route::delete('pireps/{id}/cancel', 'PirepController@cancel');
|
Route::delete('pireps/{id}/cancel', 'PirepController@cancel');
|
||||||
|
|
||||||
Route::get('pireps/{id}/acars/geojson', 'PirepController@acars_geojson');
|
|
||||||
Route::post('pireps/{id}/acars/position', 'PirepController@acars_store');
|
Route::post('pireps/{id}/acars/position', 'PirepController@acars_store');
|
||||||
Route::post('pireps/{id}/acars/positions', 'PirepController@acars_store');
|
Route::post('pireps/{id}/acars/positions', 'PirepController@acars_store');
|
||||||
|
|
||||||
|
|||||||
@@ -20,9 +20,8 @@ class ApiTest extends TestCase
|
|||||||
public function testApiAuthentication()
|
public function testApiAuthentication()
|
||||||
{
|
{
|
||||||
$user = factory(User::class)->create();
|
$user = factory(User::class)->create();
|
||||||
$pirep = factory(App\Models\Pirep::class)->create();
|
|
||||||
|
|
||||||
$uri = '/api/pireps/' . $pirep->id;
|
$uri = $this->u('/user');
|
||||||
|
|
||||||
// Missing auth header
|
// Missing auth header
|
||||||
$this->get($uri)->assertStatus(401);
|
$this->get($uri)->assertStatus(401);
|
||||||
@@ -35,20 +34,17 @@ class ApiTest extends TestCase
|
|||||||
->assertStatus(401);
|
->assertStatus(401);
|
||||||
|
|
||||||
// Test upper/lower case of Authorization header, etc
|
// Test upper/lower case of Authorization header, etc
|
||||||
$response = $this->withHeaders($this->apiHeaders())->get($uri);
|
$response = $this->get($uri, $this->headers($user));
|
||||||
$response->assertStatus(200)->assertJson(['id' => $pirep->id], true);
|
$response->assertStatus(200)->assertJson(['id' => $user->id], true);
|
||||||
|
|
||||||
$this->withHeaders(['x-api-key' => $user->api_key])->get($uri)
|
$this->withHeaders(['x-api-key' => $user->api_key])->get($uri)
|
||||||
->assertStatus(200)
|
->assertJson(['id' => $user->id], true);
|
||||||
->assertJson(['id' => $pirep->id], true);
|
|
||||||
|
|
||||||
$this->withHeaders(['x-API-key' => $user->api_key])->get($uri)
|
$this->withHeaders(['x-API-key' => $user->api_key])->get($uri)
|
||||||
->assertStatus(200)
|
->assertJson(['id' => $user->id], true);
|
||||||
->assertJson(['id' => $pirep->id], true);
|
|
||||||
|
|
||||||
$this->withHeaders(['X-API-KEY' => $user->api_key])->get($uri)
|
$this->withHeaders(['X-API-KEY' => $user->api_key])->get($uri)
|
||||||
->assertStatus(200)
|
->assertJson(['id' => $user->id], true);
|
||||||
->assertJson(['id' => $pirep->id], true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -64,6 +60,27 @@ class ApiTest extends TestCase
|
|||||||
$this->get($uri)->assertStatus(401);
|
$this->get($uri)->assertStatus(401);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function testGetAirlines()
|
||||||
|
{
|
||||||
|
$size = \random_int(5, 10);
|
||||||
|
$this->user = factory(App\Models\User::class)->create([
|
||||||
|
'airline_id' => 0
|
||||||
|
]);
|
||||||
|
|
||||||
|
$airlines = factory(App\Models\Airline::class, $size)->create();
|
||||||
|
|
||||||
|
$res = $this->get($this->u('/airlines'));
|
||||||
|
$body = $res->json();
|
||||||
|
|
||||||
|
$this->assertCount($size, $body['data']);
|
||||||
|
|
||||||
|
$airline = $airlines->random();
|
||||||
|
$this->get('/api/airlines/'.$airline->id)->assertJson(['name' => $airline->name]);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make sure the airport data is returned
|
* Make sure the airport data is returned
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ class FlightTest extends TestCase
|
|||||||
$flights = factory(App\Models\Flight::class, 100)->create();
|
$flights = factory(App\Models\Flight::class, 100)->create();
|
||||||
$flight = $flights->random();
|
$flight = $flights->random();
|
||||||
|
|
||||||
$query = 'flight_id=' . $flight->id;
|
$query = 'dep_icao=' . $flight->dep_icao;
|
||||||
$req = $this->get('/api/flights/search?' . $query);
|
$req = $this->get('/api/flights/search?' . $query);
|
||||||
$body = $req->json();
|
$body = $req->json();
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ abstract class TestCase extends Illuminate\Foundation\Testing\TestCase
|
|||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
|
public static $prefix = '/api';
|
||||||
|
|
||||||
protected $app;
|
protected $app;
|
||||||
protected $baseUrl = 'http://localhost';
|
protected $baseUrl = 'http://localhost';
|
||||||
protected $connectionsToTransact = ['testing'];
|
protected $connectionsToTransact = ['testing'];
|
||||||
@@ -37,6 +39,15 @@ abstract class TestCase extends Illuminate\Foundation\Testing\TestCase
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the URL with the URI prefix
|
||||||
|
* @param $uri
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function u($uri) {
|
||||||
|
return self::$prefix . $uri;
|
||||||
|
}
|
||||||
|
|
||||||
public function __construct($name = null, array $data = [], $dataName = '') {
|
public function __construct($name = null, array $data = [], $dataName = '') {
|
||||||
parent::__construct($name, $data, $dataName);
|
parent::__construct($name, $data, $dataName);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
#
|
#
|
||||||
airlines:
|
#airlines:
|
||||||
- id: 1
|
# - id: 1
|
||||||
icao: VMS
|
# icao: VMS
|
||||||
iata: VM
|
# iata: VM
|
||||||
name: phpvms airlines
|
# name: phpvms airlines
|
||||||
active: 1
|
# active: 1
|
||||||
created_at: now
|
# created_at: now
|
||||||
updated_at: now
|
# updated_at: now
|
||||||
|
|
||||||
users:
|
users:
|
||||||
- id: 1
|
- id: 1
|
||||||
|
|||||||
Reference in New Issue
Block a user