diff --git a/app/Http/Controllers/Api/BaseController.php b/app/Http/Controllers/Api/BaseController.php new file mode 100644 index 00000000..276db222 --- /dev/null +++ b/app/Http/Controllers/Api/BaseController.php @@ -0,0 +1,18 @@ +json( + ['message' => 'hi'], + 200 + ); + } +} diff --git a/app/Http/Controllers/Api/FlightController.php b/app/Http/Controllers/Api/FlightController.php new file mode 100644 index 00000000..f0b068d6 --- /dev/null +++ b/app/Http/Controllers/Api/FlightController.php @@ -0,0 +1,39 @@ +airline) { + $airline = Airline::where('code', $request->airline)->first()->id; + $where['airline_id'] = $airline; + } + + if($request->depICAO) { + $airport = Airport::where('icao', $request->depICAO)->first()->id; + $where['dpt_airport_id'] = $airport; + } + + if($request->arrICAO) { + $airport = Airport::where('icao', $request->depICAO)->first()->id; + $where['dpt_airport_id'] = $airport; + } + + $flights = Flight::where($where)->get(); + return fractal($flights, new FlightTransformer())->respond(); + } +} diff --git a/app/Http/Middleware/MeasureExecutionTime.php b/app/Http/Middleware/MeasureExecutionTime.php new file mode 100644 index 00000000..0988a841 --- /dev/null +++ b/app/Http/Middleware/MeasureExecutionTime.php @@ -0,0 +1,40 @@ +getContent(), true) + [ + 'execution_time' => $executionTime, + ]; + + // Change the content of your response + $response->setData($content); + + // Return the response + return $response; + } +} diff --git a/app/Models/traits/Uuids.php b/app/Models/Traits/Uuids.php similarity index 100% rename from app/Models/traits/Uuids.php rename to app/Models/Traits/Uuids.php diff --git a/app/Models/Transformers/FlightTransformer.php b/app/Models/Transformers/FlightTransformer.php new file mode 100644 index 00000000..cdc9f423 --- /dev/null +++ b/app/Models/Transformers/FlightTransformer.php @@ -0,0 +1,44 @@ + $flight->id, + 'airline' => [ + 'id' => $flight->airline->id, + 'code' => $flight->airline->code, + 'name' => $flight->airline->name, + ], + 'dpt' => [ + 'id' => $flight->dpt_airport->id, + 'icao' => $flight->dpt_airport->icao, + 'name' => $flight->dpt_airport->name, + ], + 'arr' => [ + 'id' => $flight->arr_airport->id, + 'icao' => $flight->arr_airport->icao, + 'name' => $flight->arr_airport->name, + ], + 'alt' => [], + ]; + + if($flight->alt_airport_id) { + $flight['alt'] = [ + 'id' => $flight->alt_airport->id, + 'icao' => $flight->alt_airport->icao, + 'name' => $flight->alt_airport->name, + ]; + } + + return $ret; + } +} diff --git a/app/Providers/RouteServiceProvider.php b/app/Providers/RouteServiceProvider.php index 334599a9..d867a2a3 100755 --- a/app/Providers/RouteServiceProvider.php +++ b/app/Providers/RouteServiceProvider.php @@ -66,7 +66,10 @@ class RouteServiceProvider extends ServiceProvider protected function mapApiRoutes() { Route::group([ - 'middleware' => 'api', + 'middleware' => [ + 'api', + \App\Http\Middleware\MeasureExecutionTime::class + ], 'namespace' => $this->namespace."\\API", 'prefix' => 'api', 'as' => 'api.', diff --git a/bootstrap/app.php b/bootstrap/app.php index f2801adf..c210fa86 100755 --- a/bootstrap/app.php +++ b/bootstrap/app.php @@ -11,6 +11,8 @@ | */ +define('LUMEN_START', microtime(true)); + $app = new Illuminate\Foundation\Application( realpath(__DIR__.'/../') ); diff --git a/config/app.php b/config/app.php index cbf29075..2e715406 100755 --- a/config/app.php +++ b/config/app.php @@ -58,6 +58,8 @@ return [ InfyOm\AdminLTETemplates\AdminLTETemplatesServiceProvider::class, Zizaco\Entrust\EntrustServiceProvider::class, anlutro\LaravelSettings\ServiceProvider::class, + Spatie\Fractal\FractalServiceProvider::class, + /* * Application Service Providers... @@ -72,7 +74,6 @@ return [ ], 'aliases' => [ - 'App' => Illuminate\Support\Facades\App::class, 'Artisan' => Illuminate\Support\Facades\Artisan::class, 'Auth' => Illuminate\Support\Facades\Auth::class, @@ -87,8 +88,13 @@ return [ 'Entrust' => Zizaco\Entrust\EntrustFacade::class, 'Event' => Illuminate\Support\Facades\Event::class, 'File' => Illuminate\Support\Facades\File::class, + 'Flash' => Laracasts\Flash\Flash::class, + 'Form' => Collective\Html\FormFacade::class, + 'Fractal' => Spatie\Fractal\FractalFacade::class, 'Gate' => Illuminate\Support\Facades\Gate::class, + 'Geotools' => Toin0u\Geotools\Facade\Geotools::class, 'Hash' => Illuminate\Support\Facades\Hash::class, + 'Html' => Collective\Html\HtmlFacade::class, 'Lang' => Illuminate\Support\Facades\Lang::class, 'Log' => Illuminate\Support\Facades\Log::class, 'Mail' => Illuminate\Support\Facades\Mail::class, @@ -102,17 +108,13 @@ return [ 'Route' => Illuminate\Support\Facades\Route::class, 'Schema' => Illuminate\Support\Facades\Schema::class, 'Session' => Illuminate\Support\Facades\Session::class, + 'Setting' => anlutro\LaravelSettings\Facade::class, 'Storage' => Illuminate\Support\Facades\Storage::class, 'URL' => Illuminate\Support\Facades\URL::class, + 'Utils' => App\Facades\Utils::class, 'Validator' => Illuminate\Support\Facades\Validator::class, 'View' => Illuminate\Support\Facades\View::class, - 'Form' => Collective\Html\FormFacade::class, - 'Html' => Collective\Html\HtmlFacade::class, - 'Flash' => Laracasts\Flash\Flash::class, 'Yaml' => Symfony\Component\Yaml\Yaml::class, - 'Geotools' => Toin0u\Geotools\Facade\Geotools::class, - 'Setting' => anlutro\LaravelSettings\Facade::class, - 'Utils' => App\Facades\Utils::class, ], ]; diff --git a/config/laravel-fractal.php b/config/laravel-fractal.php new file mode 100644 index 00000000..25d5c5f8 --- /dev/null +++ b/config/laravel-fractal.php @@ -0,0 +1,18 @@ + '', + +]; diff --git a/routes/api.php b/routes/api.php index 6b907f39..409d0085 100755 --- a/routes/api.php +++ b/routes/api.php @@ -13,6 +13,8 @@ use Illuminate\Http\Request; | */ -Route::get('/user', function (Request $request) { - return $request->user(); -})->middleware('auth:api'); +Route::group([], function () { + + Route::match(['get'], 'status', 'BaseController@status'); + Route::match(['get'], 'flights/search', 'FlightController@search'); +});