finish acceptance tests and refactor IotaCodesClient to service container
This commit is contained in:
@@ -38,15 +38,18 @@ class AirportController extends Controller
|
||||
*/
|
||||
public function resourceList(Request $request)
|
||||
{
|
||||
$client = IotaClient::create();
|
||||
$collection = $client->listAirports($request->input('autocomplete'));
|
||||
$iotaCodesClient = app('IotaCodesClient');
|
||||
$airportsCollection = $iotaCodesClient->listAirports($request->input('autocomplete'));
|
||||
if (! $airportsCollection) {
|
||||
return $this->returnErrorMessage('failed to fetch airport list from IOTA api', 400);
|
||||
}
|
||||
|
||||
//add pagination
|
||||
$per_page = $request->input('per_page', 10);
|
||||
$page = $request->input('page', 1);
|
||||
$paginator = new LengthAwarePaginator(
|
||||
$collection->forPage($page, $per_page),
|
||||
$collection->count(),
|
||||
$airportsCollection->forPage($page, $per_page),
|
||||
$airportsCollection->count(),
|
||||
$per_page,
|
||||
$page
|
||||
);
|
||||
@@ -74,9 +77,9 @@ class AirportController extends Controller
|
||||
*/
|
||||
public function getAirport(Request $request, $code)
|
||||
{
|
||||
$client = IotaClient::create();
|
||||
$iotaCodesClient = app('IotaCodesClient');
|
||||
|
||||
$airport = $client->getAirport($code);
|
||||
$airport = $iotaCodesClient->getAirport($code);
|
||||
if (is_null($airport)) {
|
||||
return $this->returnErrorMessage('not a valid airport code', 400);
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ class Controller extends BaseController
|
||||
*/
|
||||
protected function JsonApiResponse(ResourceInterface $resource, $statusCode, $includes = '')
|
||||
{
|
||||
$manager = new Manager();
|
||||
$manager = app('FractalManager');
|
||||
$manager->setSerializer(new JsonApiSerializer('http://docker.dev:8080'));
|
||||
$manager->parseIncludes($includes);
|
||||
|
||||
|
||||
@@ -46,11 +46,9 @@ class FlightController extends Controller
|
||||
$page
|
||||
);
|
||||
|
||||
$result = (new Collection($paginator, new TripTransformer(), 'trips'))
|
||||
$result = (new Collection($paginator, new FlightTransform(), 'trips'))
|
||||
->setPaginator(new IlluminatePaginatorAdapter($paginator));
|
||||
|
||||
$result = new Collection($flightCollection, new FlightTransform(), 'flights');
|
||||
|
||||
return $this->JsonApiResponse($result, 200);
|
||||
}
|
||||
|
||||
@@ -98,10 +96,10 @@ class FlightController extends Controller
|
||||
{
|
||||
/** @var \App\Libraries\Trips\Models\Flights $flight */
|
||||
$flight = Flights::find($id);
|
||||
$deleted = $flight->delete();
|
||||
if (! is_null($flight)) {
|
||||
$deleted = $flight->delete();
|
||||
}
|
||||
|
||||
$result = new Item($flight, new FlightTransform(), 'flights');
|
||||
|
||||
return $this->JsonApiResponse($result, 200);
|
||||
return response()->json(null, 204);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ class TripController extends Controller
|
||||
return $this->returnErrorMessage('destination not set', 400);
|
||||
}
|
||||
|
||||
$client = IotaClient::create();
|
||||
$client = app('IotaCodesClient');
|
||||
$airport = $client->getAirport($destination);
|
||||
if (is_null($airport)) {
|
||||
return $this->returnErrorMessage('destination not a valid airport code', 400);
|
||||
|
||||
Reference in New Issue
Block a user