2018-01-06 00:45:34 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Api;
|
|
|
|
|
2019-07-16 03:51:35 +08:00
|
|
|
use App\Contracts\Controller;
|
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
|
|
|
|
2018-03-20 09:50:40 +08:00
|
|
|
/**
|
|
|
|
* Class FleetController
|
|
|
|
*/
|
|
|
|
class FleetController extends Controller
|
2018-01-06 00:45:34 +08:00
|
|
|
{
|
2018-08-27 00:40:04 +08:00
|
|
|
private $aircraftRepo;
|
|
|
|
private $subfleetRepo;
|
2018-01-06 00:45:34 +08:00
|
|
|
|
2018-02-21 12:33:09 +08:00
|
|
|
/**
|
|
|
|
* FleetController constructor.
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
2018-02-21 12:33:09 +08:00
|
|
|
* @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
|
2018-03-20 09:50:40 +08:00
|
|
|
->with(['aircraft', 'airline', 'fares', 'ranks'])
|
|
|
|
->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
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
2018-03-20 09:50:40 +08:00
|
|
|
* @param $id
|
2018-01-06 03:00:45 +08:00
|
|
|
* @param Request $request
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
2018-01-06 03:00:45 +08:00
|
|
|
* @return AircraftResource
|
|
|
|
*/
|
|
|
|
public function get_aircraft($id, Request $request)
|
|
|
|
{
|
|
|
|
$where = [];
|
2018-03-20 09:50:40 +08:00
|
|
|
if ($request->filled('type')) {
|
2018-01-06 03:00:45 +08:00
|
|
|
$where[$request->get('type')] = $id;
|
|
|
|
} else {
|
|
|
|
$where['id'] = $id;
|
|
|
|
}
|
|
|
|
|
|
|
|
$aircraft = $this->aircraftRepo
|
2018-03-20 09:50:40 +08:00
|
|
|
->with(['subfleet', 'subfleet.fares'])
|
|
|
|
->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
|
|
|
}
|
|
|
|
}
|