Check Aircraft Availability (#1177)
* Check Aircraft Availability before Prefile Check if the aircraft is available for flight (State : Parked / On Ground). If not throw new exception AircraftNotAvailable * Add Exception AircraftNotAvailable exception, used by PirepService during prefile checks.
This commit is contained in:
parent
ee61de62fa
commit
594d0eb222
38
app/Exceptions/AircraftNotAvailable.php
Normal file
38
app/Exceptions/AircraftNotAvailable.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
use App\Models\Aircraft;
|
||||
|
||||
class AircraftNotAvailable extends AbstractHttpException
|
||||
{
|
||||
public const MESSAGE = 'The aircraft is not available for flight';
|
||||
|
||||
private $aircraft;
|
||||
|
||||
public function __construct(Aircraft $aircraft)
|
||||
{
|
||||
$this->aircraft = $aircraft;
|
||||
parent::__construct(
|
||||
400,
|
||||
static::MESSAGE
|
||||
);
|
||||
}
|
||||
|
||||
public function getErrorType(): string
|
||||
{
|
||||
return 'aircraft-not-available';
|
||||
}
|
||||
|
||||
public function getErrorDetails(): string
|
||||
{
|
||||
return $this->getMessage();
|
||||
}
|
||||
|
||||
public function getErrorMetadata(): array
|
||||
{
|
||||
return [
|
||||
'aircraft_id' => $this->aircraft->id,
|
||||
];
|
||||
}
|
||||
}
|
@ -11,6 +11,7 @@ use App\Events\PirepRejected;
|
||||
use App\Events\UserStatsChanged;
|
||||
use App\Exceptions\AircraftInvalid;
|
||||
use App\Exceptions\AircraftNotAtAirport;
|
||||
use App\Exceptions\AircraftNotAvailable;
|
||||
use App\Exceptions\AircraftPermissionDenied;
|
||||
use App\Exceptions\AirportNotFound;
|
||||
use App\Exceptions\PirepCancelNotAllowed;
|
||||
@ -19,6 +20,7 @@ use App\Exceptions\UserNotAtAirport;
|
||||
use App\Models\Acars;
|
||||
use App\Models\Aircraft;
|
||||
use App\Models\Enums\AcarsType;
|
||||
use App\Models\Enums\AircraftState;
|
||||
use App\Models\Enums\FlightType;
|
||||
use App\Models\Enums\PirepSource;
|
||||
use App\Models\Enums\PirepState;
|
||||
@ -132,13 +134,21 @@ class PirepService extends Service
|
||||
throw new AircraftPermissionDenied($user, $pirep->aircraft);
|
||||
}
|
||||
|
||||
// See if this aircraft is at the departure airport
|
||||
// See if this aircraft is valid
|
||||
/** @var Aircraft $aircraft */
|
||||
$aircraft = $this->aircraftRepo->findWithoutFail($pirep->aircraft_id);
|
||||
if ($aircraft === null) {
|
||||
throw new AircraftInvalid($aircraft);
|
||||
}
|
||||
|
||||
// See if this aircraft is available for flight
|
||||
/** @var Aircraft $aircraft */
|
||||
$aircraft = $this->aircraftRepo->where('id', $pirep->aircraft_id)->where('state', AircraftState::PARKED)->first();
|
||||
if ($aircraft === null) {
|
||||
throw new AircraftNotAvailable($pirep->aircraft);
|
||||
}
|
||||
|
||||
// See if this aircraft is at the departure airport
|
||||
/* @noinspection NotOptimalIfConditionsInspection */
|
||||
if (setting('pireps.only_aircraft_at_dpt_airport') && $aircraft->airport_id !== $pirep->dpt_airport_id) {
|
||||
throw new AircraftNotAtAirport($pirep->aircraft);
|
||||
|
Loading…
Reference in New Issue
Block a user