Change the filtering to operate without being in the service layer #174
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Http\Controllers\Api;
|
namespace App\Http\Controllers\Api;
|
||||||
|
|
||||||
|
use App\Repositories\Criteria\WhereCriteria;
|
||||||
use App\Services\FlightService;
|
use App\Services\FlightService;
|
||||||
use Auth;
|
use Auth;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
@@ -36,7 +37,15 @@ class FlightController extends RestController
|
|||||||
public function index(Request $request)
|
public function index(Request $request)
|
||||||
{
|
{
|
||||||
$user = Auth::user();
|
$user = Auth::user();
|
||||||
$flights = $this->flightSvc->filterFlights($user)->paginate();
|
|
||||||
|
$where = ['active' => true];
|
||||||
|
if (setting('pilots.only_flights_from_current', false)) {
|
||||||
|
$where['dpt_airport_id'] = $user->curr_airport_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
$flights = $this->flightRepo
|
||||||
|
->whereOrder($where, 'flight_number', 'asc')
|
||||||
|
->paginate();
|
||||||
|
|
||||||
foreach($flights as $flight) {
|
foreach($flights as $flight) {
|
||||||
$this->flightSvc->filterSubfleets($user, $flight);
|
$this->flightSvc->filterSubfleets($user, $flight);
|
||||||
@@ -67,9 +76,15 @@ class FlightController extends RestController
|
|||||||
$user = Auth::user();
|
$user = Auth::user();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
$where = ['active' => true];
|
||||||
|
if (setting('pilots.only_flights_from_current')) {
|
||||||
|
$where['dpt_airport_id'] = Auth::user()->curr_airport_id;
|
||||||
|
}
|
||||||
|
|
||||||
$this->flightRepo->searchCriteria($request);
|
$this->flightRepo->searchCriteria($request);
|
||||||
$this->flightRepo->pushCriteria(new RequestCriteria($request));
|
$this->flightRepo->pushCriteria(new RequestCriteria($request));
|
||||||
$flights = $this->flightSvc->filterFlights($user)->paginate();
|
$this->flightRepo->pushCriteria(new WhereCriteria($request, $where));
|
||||||
|
$flights = $this->flightRepo->paginate();
|
||||||
} catch (RepositoryException $e) {
|
} catch (RepositoryException $e) {
|
||||||
return response($e, 503);
|
return response($e, 503);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ class FlightTest extends TestCase
|
|||||||
public function testFindAllFlights()
|
public function testFindAllFlights()
|
||||||
{
|
{
|
||||||
$this->user = factory(App\Models\User::class)->create();
|
$this->user = factory(App\Models\User::class)->create();
|
||||||
factory(App\Models\Flight::class, 70)->create([
|
factory(App\Models\Flight::class, 20)->create([
|
||||||
'airline_id' => $this->user->airline_id
|
'airline_id' => $this->user->airline_id
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@@ -81,7 +81,7 @@ class FlightTest extends TestCase
|
|||||||
$this->assertEquals(2, $body['meta']['last_page']);
|
$this->assertEquals(2, $body['meta']['last_page']);
|
||||||
|
|
||||||
$res = $this->get('/api/flights?page=2');
|
$res = $this->get('/api/flights?page=2');
|
||||||
$res->assertJsonCount(20, 'data');
|
$res->assertJsonCount(5, 'data');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testFlightSearchApi()
|
public function testFlightSearchApi()
|
||||||
|
|||||||
Reference in New Issue
Block a user