Flight/Subfleet fares not returning in API #899 (#900)

Make sure proper fares are returned from the API #899
This commit is contained in:
Nabeel S
2020-10-24 15:11:08 -04:00
committed by GitHub
parent b83f7dcac8
commit 1be68d1e63
13 changed files with 206 additions and 95 deletions

View File

@@ -92,8 +92,9 @@ class CreateDatabase extends Command
}
if ($this->option('reset') === true) {
$cmd = ['rm', '-rf', config($dbkey.'database')];
$this->runCommand($cmd);
if (file_exists($dbPath)) {
unlink(config($dbkey.'database'));
}
}
if (!file_exists($dbPath)) {

View File

@@ -54,9 +54,13 @@ class FlightController extends Controller
*/
public function get($id)
{
/** @var \App\Models\User $user */
$user = Auth::user();
/** @var \App\Models\Flight $flight */
$flight = $this->flightRepo->with([
'airline',
'fares',
'subfleets',
'subfleets.aircraft',
'subfleets.fares',
@@ -66,7 +70,7 @@ class FlightController extends Controller
},
])->find($id);
$this->flightSvc->filterSubfleets(Auth::user(), $flight);
$flight = $this->flightSvc->filterSubfleets($user, $flight);
return new FlightResource($flight);
}
@@ -109,6 +113,7 @@ class FlightController extends Controller
$flights = $this->flightRepo
->with([
'airline',
'fares',
'subfleets',
'subfleets.aircraft',
'subfleets.fares',
@@ -124,7 +129,7 @@ class FlightController extends Controller
// TODO: Remove any flights here that a user doesn't have permissions to
foreach ($flights as $flight) {
$this->flightSvc->filterSubfleets(Auth::user(), $flight);
$this->flightSvc->filterSubfleets($user, $flight);
}
return FlightResource::collection($flights);

View File

@@ -61,7 +61,8 @@ class UserController extends Controller
*/
protected function getUserId(Request $request)
{
if ($request->get('id') === null) {
$id = $request->get('id');
if ($id === null || $id === 'me') {
return Auth::user()->id;
}

View File

@@ -3,6 +3,7 @@
namespace App\Http\Resources;
use App\Contracts\Resource;
use App\Services\FareService;
/**
* @mixin \App\Models\Fare
@@ -11,13 +12,17 @@ class Fare extends Resource
{
public function toArray($request)
{
/** @var FareService $fareSvc */
$fareSvc = app(FareService::class);
$fare = $fareSvc->getFares($this);
return [
'id' => $this->id,
'code' => $this->code,
'name' => $this->name,
'price' => $this->price,
'cost' => $this->cost,
'capacity' => $this->capacity,
'id' => $fare->id,
'code' => $fare->code,
'name' => $fare->name,
'capacity' => $fare->capacity,
'cost' => $fare->cost,
'price' => $fare->price,
'type' => $this->type,
'notes' => $this->notes,
'active' => $this->active,

View File

@@ -58,6 +58,7 @@ class Flight extends Resource
$res['airline'] = new Airline($this->airline);
$res['subfleets'] = Subfleet::collection($this->whenLoaded('subfleets'));
$res['fares'] = Fare::collection($this->whenLoaded('fares'));
$res['fields'] = $this->setFields();
// Simbrief info

View File

@@ -580,6 +580,7 @@ class RouteServiceProvider extends ServiceProvider
Route::post('user/bids', 'UserController@bids');
Route::delete('user/bids', 'UserController@bids');
Route::get('users/me', 'UserController@index');
Route::get('users/{id}', 'UserController@get');
Route::get('users/{id}/fleet', 'UserController@fleet');
Route::get('users/{id}/pireps', 'UserController@pireps');

View File

@@ -45,6 +45,7 @@ class BidService extends Service
{
$bids = Bid::with([
'flight',
'flight.fares',
'flight.simbrief',
'flight.subfleets',
'flight.subfleets.aircraft',

View File

@@ -60,13 +60,13 @@ class FareService extends Service
}
/**
* Get fares
* Get a fare with the proper prices/costs populated in the pivot
*
* @param $fare
*
* @return mixed
*/
protected function getFares($fare)
public function getFares($fare)
{
$pivot = $fare->pivot;
if (filled($pivot->price)) {

View File

@@ -16,6 +16,7 @@ use App\Support\Units\Time;
class FlightService extends Service
{
private $airportSvc;
private $fareSvc;
private $flightRepo;
private $navDataRepo;
private $userSvc;
@@ -24,17 +25,20 @@ class FlightService extends Service
* FlightService constructor.
*
* @param AirportService $airportSvc
* @param FareService $fareSvc
* @param FlightRepository $flightRepo
* @param NavdataRepository $navdataRepo
* @param UserService $userSvc
*/
public function __construct(
AirportService $airportSvc,
FareService $fareSvc,
FlightRepository $flightRepo,
NavdataRepository $navdataRepo,
UserService $userSvc
) {
$this->airportSvc = $airportSvc;
$this->fareSvc = $fareSvc;
$this->flightRepo = $flightRepo;
$this->navDataRepo = $navdataRepo;
$this->userSvc = $userSvc;