2018-01-06 00:45:34 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Api;
|
|
|
|
|
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;
|
2018-02-21 12:33:09 +08:00
|
|
|
use App\Repositories\AircraftRepository;
|
|
|
|
use App\Repositories\SubfleetRepository;
|
|
|
|
use Illuminate\Http\Request;
|
2018-01-06 00:45:34 +08:00
|
|
|
|
|
|
|
class FleetController extends RestController
|
|
|
|
{
|
|
|
|
protected $aircraftRepo, $subfleetRepo;
|
|
|
|
|
2018-02-21 12:33:09 +08:00
|
|
|
/**
|
|
|
|
* FleetController constructor.
|
|
|
|
* @param AircraftRepository $aircraftRepo
|
|
|
|
* @param SubfleetRepository $subfleetRepo
|
|
|
|
*/
|
2018-01-06 00:45:34 +08:00
|
|
|
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'])
|
2018-02-11 07:34:46 +08:00
|
|
|
->paginate();
|
2018-01-06 03:00:45 +08:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
$aircraft = $this->aircraftRepo
|
2018-01-24 11:40:34 +08:00
|
|
|
->with(['subfleet', 'subfleet.fares'])
|
2018-01-06 03:00:45 +08:00
|
|
|
->findWhere($where)
|
|
|
|
->first();
|
2018-01-06 00:45:34 +08:00
|
|
|
|
2018-01-06 03:00:45 +08:00
|
|
|
return new AircraftResource($aircraft);
|
2018-01-06 00:45:34 +08:00
|
|
|
}
|
|
|
|
}
|