Cleanup the cancelled PIREP logic

This commit is contained in:
Nabeel Shahzad 2018-05-11 12:08:55 -05:00
parent 605bf477ad
commit bc7fccfb95
5 changed files with 28 additions and 26 deletions

View File

@ -58,7 +58,7 @@ class AcarsController extends Controller
*/ */
protected function checkCancelled(Pirep $pirep) protected function checkCancelled(Pirep $pirep)
{ {
if (!$pirep->allowedUpdates()) { if ($pirep->cancelled) {
throw new PirepCancelled(); throw new PirepCancelled();
} }
} }

View File

@ -102,7 +102,7 @@ class PirepController extends Controller
*/ */
protected function checkCancelled(Pirep $pirep) protected function checkCancelled(Pirep $pirep)
{ {
if (!$pirep->allowedUpdates()) { if ($pirep->cancelled) {
throw new PirepCancelled(); throw new PirepCancelled();
} }
} }

View File

@ -12,11 +12,16 @@ use PhpUnitsOfMeasure\Exception\NonStringUnitName;
/** /**
* Class Acars * Class Acars
* @param string id * @param string id
* @property mixed gs * @property string pirep_id
* @property mixed lat * @property int type
* @property mixed lon * @property string name
* @property mixed altitude * @property double lat
* @property mixed heading * @property double lon
* @property double altitude
* @property int gs
* @property int heading
* @property int order
* @property int nav_type
* @package App\Models * @package App\Models
*/ */
class Acars extends Model class Acars extends Model
@ -64,15 +69,15 @@ class Acars extends Model
'fuel' => 'float', 'fuel' => 'float',
'fuel_flow' => 'float', 'fuel_flow' => 'float',
]; ];
/*public static $sanitize = [
'sim_time' => 'carbon',
'created_at' => '',
];*/
public static $rules = [ public static $rules = [
'pirep_id' => 'required', 'pirep_id' => 'required',
]; ];
/*public static $sanitize = [
'sim_time' => 'carbon',
'created_at' => '',
];*/
/** /**
* Return a new Length unit so conversions can be made * Return a new Length unit so conversions can be made

View File

@ -33,8 +33,9 @@ use PhpUnitsOfMeasure\Exception\NonStringUnitName;
* @property integer block_time * @property integer block_time
* @property integer flight_time In minutes * @property integer flight_time In minutes
* @property integer planned_flight_time * @property integer planned_flight_time
* @property mixed planned_distance * @property double distance
* @property mixed distance * @property double planned_distance
* @property string route
* @property integer score * @property integer score
* @property User user * @property User user
* @property Flight|null flight * @property Flight|null flight
@ -361,6 +362,14 @@ class Pirep extends Model
$this->attributes['route'] = $route; $this->attributes['route'] = $route;
} }
/**
* Return if this is cancelled or not
*/
public function getCancelledAttribute()
{
return $this->state === PirepState::CANCELLED;
}
/** /**
* Check if this PIREP is allowed to be updated * Check if this PIREP is allowed to be updated
* @return bool * @return bool

View File

@ -32,35 +32,23 @@ use Log;
*/ */
class PirepService extends Service class PirepService extends Service
{ {
private $acarsRepo, private $geoSvc,
$flightRepo,
$geoSvc,
$navRepo,
$pilotSvc, $pilotSvc,
$pirepRepo; $pirepRepo;
/** /**
* PirepService constructor. * PirepService constructor.
* @param AcarsRepository $acarsRepo
* @param FlightRepository $flightRepo
* @param GeoService $geoSvc * @param GeoService $geoSvc
* @param NavdataRepository $navRepo
* @param PirepRepository $pirepRepo * @param PirepRepository $pirepRepo
* @param UserService $pilotSvc * @param UserService $pilotSvc
*/ */
public function __construct( public function __construct(
AcarsRepository $acarsRepo,
FlightRepository $flightRepo,
GeoService $geoSvc, GeoService $geoSvc,
NavdataRepository $navRepo,
PirepRepository $pirepRepo, PirepRepository $pirepRepo,
UserService $pilotSvc UserService $pilotSvc
) { ) {
$this->acarsRepo = $acarsRepo;
$this->flightRepo = $flightRepo;
$this->geoSvc = $geoSvc; $this->geoSvc = $geoSvc;
$this->pilotSvc = $pilotSvc; $this->pilotSvc = $pilotSvc;
$this->navRepo = $navRepo;
$this->pirepRepo = $pirepRepo; $this->pirepRepo = $pirepRepo;
} }