Add greater than/less than search options #297

This commit is contained in:
Nabeel Shahzad
2019-05-10 16:03:04 -05:00
parent 1dae81b707
commit 5b061ba636
7 changed files with 69 additions and 10 deletions

View File

@@ -89,31 +89,34 @@ class FlightController extends Controller
*/
public function search(Request $request)
{
$user = Auth::user();
try {
$where = [
'active' => true,
'visible' => true,
];
$where = [
'active' => true,
'visible' => true,
];
// Allow the option to bypass some of these restrictions for the searches
if (!$request->filled('ignore_restrictions') || $request->ignore_restrictions === '0') {
if (setting('pilots.restrict_to_company')) {
$where['airline_id'] = Auth::user()->airline_id;
}
if (setting('pilots.only_flights_from_current')) {
$where['dpt_airport_id'] = Auth::user()->curr_airport_id;
}
}
try {
$this->flightRepo->searchCriteria($request);
$this->flightRepo->pushCriteria(new RequestCriteria($request));
$this->flightRepo->pushCriteria(new WhereCriteria($request, $where));
$this->flightRepo->pushCriteria(new RequestCriteria($request));
$flights = $this->flightRepo->paginate();
} catch (RepositoryException $e) {
return response($e, 503);
}
foreach ($flights as $flight) {
$this->flightSvc->filterSubfleets($user, $flight);
$this->flightSvc->filterSubfleets(Auth::user(), $flight);
}
return FlightResource::collection($flights);