Add lookup for aircraft as /fleet/aircraft/{id} #120
This commit is contained in:
@@ -2,9 +2,12 @@
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
use App\Repositories\AircraftRepository;
|
||||
use App\Repositories\SubfleetRepository;
|
||||
|
||||
use App\Http\Resources\Aircraft as AircraftResource;
|
||||
use App\Http\Resources\Subfleet as SubfleetResource;
|
||||
|
||||
class FleetController extends RestController
|
||||
@@ -13,10 +16,10 @@ class FleetController extends RestController
|
||||
|
||||
public function __construct(
|
||||
AircraftRepository $aircraftRepo,
|
||||
SubfleetRepository $airportRepo
|
||||
SubfleetRepository $subfleetRepo
|
||||
) {
|
||||
$this->aircraftRepo = $airportRepo;
|
||||
$this->subfleetRepo = $airportRepo;
|
||||
$this->aircraftRepo = $aircraftRepo;
|
||||
$this->subfleetRepo = $subfleetRepo;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -25,10 +28,36 @@ class FleetController extends RestController
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$airports = $this->subfleetRepo
|
||||
->with(['aircraft', 'airline', 'fares', 'ranks'])
|
||||
->paginate(50);
|
||||
$subfleets = $this->subfleetRepo
|
||||
->with(['aircraft', 'airline', 'fares', 'ranks'])
|
||||
->paginate(50);
|
||||
|
||||
return SubfleetResource::collection($airports);
|
||||
return SubfleetResource::collection($subfleets);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a specific aircraft. Query string required to specify the tail
|
||||
* /api/aircraft/XYZ?type=registration
|
||||
* @param $id
|
||||
* @param Request $request
|
||||
* @return AircraftResource
|
||||
*/
|
||||
public function get_aircraft($id, Request $request)
|
||||
{
|
||||
$where = [];
|
||||
if($request->filled('type')) {
|
||||
$where[$request->get('type')] = $id;
|
||||
} else {
|
||||
$where['id'] = $id;
|
||||
}
|
||||
|
||||
$all_aircraft = $this->aircraftRepo->all();
|
||||
$aircraft = $this->aircraftRepo
|
||||
->with(['subfleet'])
|
||||
->findWhere($where)
|
||||
->first();
|
||||
|
||||
AircraftResource::withoutWrapping();
|
||||
return new AircraftResource($aircraft);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user