2018-01-06 00:45:34 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Api;
|
|
|
|
|
2018-01-06 03:00:45 +08:00
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
2018-01-06 00:45:34 +08:00
|
|
|
use App\Repositories\AircraftRepository;
|
|
|
|
use App\Repositories\SubfleetRepository;
|
|
|
|
|
2018-01-06 03:00:45 +08:00
|
|
|
use App\Http\Resources\Aircraft as AircraftResource;
|
2018-01-06 00:45:34 +08:00
|
|
|
use App\Http\Resources\Subfleet as SubfleetResource;
|
|
|
|
|
|
|
|
class FleetController extends RestController
|
|
|
|
{
|
|
|
|
protected $aircraftRepo, $subfleetRepo;
|
|
|
|
|
|
|
|
public function __construct(
|
|
|
|
AircraftRepository $aircraftRepo,
|
2018-01-06 03:00:45 +08:00
|
|
|
SubfleetRepository $subfleetRepo
|
2018-01-06 00:45:34 +08:00
|
|
|
) {
|
2018-01-06 03:00:45 +08:00
|
|
|
$this->aircraftRepo = $aircraftRepo;
|
|
|
|
$this->subfleetRepo = $subfleetRepo;
|
2018-01-06 00:45:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return all the subfleets and the aircraft and any other associated data
|
|
|
|
* Paginated
|
|
|
|
*/
|
|
|
|
public function index()
|
|
|
|
{
|
2018-01-06 03:00:45 +08:00
|
|
|
$subfleets = $this->subfleetRepo
|
|
|
|
->with(['aircraft', 'airline', 'fares', 'ranks'])
|
|
|
|
->paginate(50);
|
|
|
|
|
|
|
|
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();
|
2018-01-06 00:45:34 +08:00
|
|
|
|
2018-01-06 03:00:45 +08:00
|
|
|
AircraftResource::withoutWrapping();
|
|
|
|
return new AircraftResource($aircraft);
|
2018-01-06 00:45:34 +08:00
|
|
|
}
|
|
|
|
}
|