Refactor fares inheritance #905 (#906)

This commit is contained in:
Nabeel S
2020-10-27 18:46:15 -04:00
committed by GitHub
parent 060bebf8fe
commit dc7efc981c
8 changed files with 187 additions and 121 deletions

View File

@@ -9,6 +9,7 @@ use App\Http\Resources\Navdata as NavdataResource;
use App\Models\SimBrief;
use App\Repositories\Criteria\WhereCriteria;
use App\Repositories\FlightRepository;
use App\Services\FareService;
use App\Services\FlightService;
use Exception;
use Illuminate\Http\Request;
@@ -18,19 +19,26 @@ use Prettus\Repository\Exceptions\RepositoryException;
class FlightController extends Controller
{
/** @var \App\Services\FareService */
private $fareSvc;
/** @var \App\Repositories\FlightRepository */
private $flightRepo;
/** @var \App\Services\FlightService */
private $flightSvc;
/**
* FlightController constructor.
*
* @param FareService $fareSvc
* @param FlightRepository $flightRepo
* @param FlightService $flightSvc
*/
public function __construct(
FareService $fareSvc,
FlightRepository $flightRepo,
FlightService $flightSvc
) {
$this->fareSvc = $fareSvc;
$this->flightRepo = $flightRepo;
$this->flightSvc = $flightSvc;
}
@@ -71,6 +79,7 @@ class FlightController extends Controller
])->find($id);
$flight = $this->flightSvc->filterSubfleets($user, $flight);
$flight = $this->fareSvc->getReconciledFaresForFlight($flight);
return new FlightResource($flight);
}
@@ -130,6 +139,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($user, $flight);
$this->fareSvc->getReconciledFaresForFlight($flight);
}
return FlightResource::collection($flights);

View File

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

View File

@@ -58,7 +58,6 @@ 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