Cleanup and move subfleet/rank settings to FleetService class
This commit is contained in:
parent
f0977b48e5
commit
3aa4b8a410
@ -6,6 +6,7 @@ use App\Http\Requests\CreateRankRequest;
|
||||
use App\Http\Requests\UpdateRankRequest;
|
||||
use App\Repositories\RankRepository;
|
||||
use App\Repositories\SubfleetRepository;
|
||||
use App\Services\FleetService;
|
||||
use Cache;
|
||||
use Flash;
|
||||
use Illuminate\Http\Request;
|
||||
@ -15,17 +16,22 @@ use Response;
|
||||
class RankController extends BaseController
|
||||
{
|
||||
/** @var RankRepository */
|
||||
private $rankRepository, $subfleetRepo;
|
||||
private $fleetSvc,
|
||||
$rankRepository,
|
||||
$subfleetRepo;
|
||||
|
||||
/**
|
||||
* RankController constructor.
|
||||
* @param FleetService $fleetSvc
|
||||
* @param RankRepository $rankingRepo
|
||||
* @param SubfleetRepository $subfleetRepo
|
||||
*/
|
||||
public function __construct(
|
||||
FleetService $fleetSvc,
|
||||
RankRepository $rankingRepo,
|
||||
SubfleetRepository $subfleetRepo
|
||||
) {
|
||||
$this->fleetSvc = $fleetSvc;
|
||||
$this->rankRepository = $rankingRepo;
|
||||
$this->subfleetRepo = $subfleetRepo;
|
||||
}
|
||||
@ -204,19 +210,22 @@ class RankController extends BaseController
|
||||
|
||||
// add aircraft to flight
|
||||
if ($request->isMethod('post')) {
|
||||
$rank->subfleets()->syncWithoutDetaching([$request->subfleet_id]);
|
||||
$subfleet = $this->subfleetRepo->find($request->input('subfleet_id'));
|
||||
$this->fleetSvc->addSubfleetToRank($subfleet, $rank);
|
||||
}
|
||||
|
||||
elseif($request->isMethod('put')) {
|
||||
$override = [];
|
||||
$subfleet = $this->subfleetRepo->find($request->input('subfleet_id'));
|
||||
$override[$request->name] = $request->value;
|
||||
$rank->subfleets()->updateExistingPivot($subfleet->id, $override);
|
||||
$subfleet = $this->subfleetRepo->find($request->input('subfleet_id'));
|
||||
|
||||
$this->fleetSvc->addSubfleetToRank($subfleet, $rank);
|
||||
}
|
||||
|
||||
// remove aircraft from flight
|
||||
elseif ($request->isMethod('delete')) {
|
||||
$rank->subfleets()->detach($request->subfleet_id);
|
||||
$subfleet = $this->subfleetRepo->find($request->input('subfleet_id'));
|
||||
$this->fleetSvc->removeSubfleetFromRank($subfleet, $rank);
|
||||
}
|
||||
|
||||
return $this->return_subfleet_view($rank);
|
||||
|
@ -12,6 +12,7 @@ use App\Repositories\FareRepository;
|
||||
use App\Repositories\RankRepository;
|
||||
use App\Repositories\SubfleetRepository;
|
||||
use App\Services\FareService;
|
||||
use App\Services\FleetService;
|
||||
use Flash;
|
||||
use Illuminate\Http\Request;
|
||||
use Prettus\Repository\Criteria\RequestCriteria;
|
||||
@ -20,27 +21,36 @@ use Response;
|
||||
class SubfleetController extends BaseController
|
||||
{
|
||||
/** @var SubfleetRepository */
|
||||
private $aircraftRepo, $rankRepo, $subfleetRepo, $fareRepo, $fareSvc;
|
||||
private $aircraftRepo,
|
||||
$fareRepo,
|
||||
$fareSvc,
|
||||
$fleetSvc,
|
||||
$rankRepo,
|
||||
$subfleetRepo;
|
||||
|
||||
/**
|
||||
* SubfleetController constructor.
|
||||
* @param AircraftRepository $aircraftRepo
|
||||
* @param FleetService $fleetSvc
|
||||
* @param RankRepository $rankRepo
|
||||
* @param SubfleetRepository $subfleetRepo
|
||||
* @param FareRepository $fareRepo
|
||||
* @param FareService $fareSvc
|
||||
*/
|
||||
public function __construct(
|
||||
AircraftRepository $aircraftRepo,
|
||||
FleetService $fleetSvc,
|
||||
RankRepository $rankRepo,
|
||||
SubfleetRepository $subfleetRepo,
|
||||
FareRepository $fareRepo,
|
||||
FareService $fareSvc
|
||||
) {
|
||||
$this->aircraftRepo = $aircraftRepo;
|
||||
$this->rankRepo = $rankRepo;
|
||||
$this->subfleetRepo = $subfleetRepo;
|
||||
$this->fareRepo = $fareRepo;
|
||||
$this->fareSvc = $fareSvc;
|
||||
$this->fleetSvc = $fleetSvc;
|
||||
$this->rankRepo = $rankRepo;
|
||||
$this->subfleetRepo = $subfleetRepo;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -271,19 +281,22 @@ class SubfleetController extends BaseController
|
||||
* update specific rank data
|
||||
*/
|
||||
if ($request->isMethod('post')) {
|
||||
$subfleet->ranks()->syncWithoutDetaching([$request->input('rank_id')]);
|
||||
$rank = $this->fareRepo->find($request->input('rank_id'));
|
||||
$this->fleetSvc->addSubfleetToRank($subfleet, $rank);
|
||||
}
|
||||
|
||||
elseif ($request->isMethod('put')) {
|
||||
$override = [];
|
||||
$rank = $this->fareRepo->find($request->input('rank_id'));
|
||||
$override[$request->name] = $request->value;
|
||||
$subfleet->ranks()->updateExistingPivot($rank->id, $override);
|
||||
|
||||
$this->fleetSvc->addSubfleetToRank($subfleet, $rank, $override);
|
||||
}
|
||||
|
||||
// dissassociate fare from teh aircraft
|
||||
elseif ($request->isMethod('delete')) {
|
||||
$subfleet->ranks()->detach($request->input('rank_id'));
|
||||
$rank = $this->fareRepo->find($request->input('rank_id'));
|
||||
$this->fleetSvc->removeSubfleetFromRank($subfleet, $rank);
|
||||
}
|
||||
|
||||
$subfleet->save();
|
||||
|
@ -1,8 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
class AircraftService extends BaseService
|
||||
{
|
||||
|
||||
}
|
37
app/Services/FleetService.php
Normal file
37
app/Services/FleetService.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\Rank;
|
||||
use App\Models\Subfleet;
|
||||
|
||||
class FleetService extends BaseService
|
||||
{
|
||||
/**
|
||||
* @param Subfleet $subfleet
|
||||
* @param Rank $rank
|
||||
* @param array $overrides
|
||||
* @return Subfleet
|
||||
*/
|
||||
public function addSubfleetToRank(Subfleet $subfleet, Rank $rank, array $overrides=[])
|
||||
{
|
||||
$subfleet->ranks()->syncWithoutDetaching([$rank->id]);
|
||||
|
||||
if($overrides) {
|
||||
$subfleet->ranks()->updateExistingPivot($rank->id, $overrides);
|
||||
}
|
||||
|
||||
$subfleet->save();
|
||||
$subfleet->refresh();
|
||||
return $subfleet;
|
||||
}
|
||||
|
||||
public function removeSubfleetFromRank(Subfleet $subfleet, Rank $rank)
|
||||
{
|
||||
$subfleet->ranks()->detach($rank->id);
|
||||
|
||||
$subfleet->save();
|
||||
$subfleet->refresh();
|
||||
return $subfleet;
|
||||
}
|
||||
}
|
@ -270,4 +270,13 @@ class FinanceTest extends TestCase
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the pilot pay, derived from the rank, and then if there
|
||||
* are any overrides from a PIREP
|
||||
*/
|
||||
public function testGetPilotPay()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user