Some Error handling and acceptance tests
This commit is contained in:
@@ -63,11 +63,15 @@ class Client
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $code
|
||||
* @return Collection
|
||||
*/
|
||||
public function getAirport($code)
|
||||
{
|
||||
$uri = '/api/v6/airports';
|
||||
$cacheKey = 'airport.'.$code;
|
||||
$cacheMinutes = 60;
|
||||
$cacheMinutes = 1;
|
||||
|
||||
$response = app('cache')->get($cacheKey, function () use ($cacheKey, $cacheMinutes, $uri, $code) {
|
||||
try {
|
||||
@@ -81,7 +85,7 @@ class Client
|
||||
]);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
//todo handle error
|
||||
return new Collection();
|
||||
}
|
||||
|
||||
$result = $response->getBody()->getContents();
|
||||
|
||||
@@ -7,6 +7,15 @@ use League\Fractal\TransformerAbstract;
|
||||
|
||||
class FlightTransform extends TransformerAbstract
|
||||
{
|
||||
/**
|
||||
* List of resources possible to include
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $availableIncludes = [
|
||||
'trips'
|
||||
];
|
||||
|
||||
/**
|
||||
* Turn this item object into a generic array
|
||||
*
|
||||
@@ -17,10 +26,23 @@ class FlightTransform extends TransformerAbstract
|
||||
return [
|
||||
'id' => $flight->id,
|
||||
'name' => $flight->destination,
|
||||
'trips' => $flight->trips()->get(),
|
||||
'links' => [
|
||||
'rel' => 'self',
|
||||
'uri' => '/flights/'.$flight->id,
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Include Trips
|
||||
*
|
||||
* @return \League\Fractal\Resource\ResourceAbstract
|
||||
*/
|
||||
public function includeTrips(Flights $flight)
|
||||
{
|
||||
$flights = $flight->trips()->get();
|
||||
|
||||
return $this->collection($flights, new TripTransformer());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,4 +16,15 @@ class Trips extends Model
|
||||
{
|
||||
return $this->belongsToMany(Flights::class, 'trip_flights');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function toArray()
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'name' => $this->name,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ class TripTransformer extends TransformerAbstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Include Author
|
||||
* Include Flights
|
||||
*
|
||||
* @return \League\Fractal\Resource\ResourceAbstract
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user