Allow any airport to be flown from #783
This commit is contained in:
@@ -26,6 +26,13 @@
|
|||||||
options:
|
options:
|
||||||
type: boolean
|
type: boolean
|
||||||
description: If an airport isn't added, try to look it up when adding schedules
|
description: If an airport isn't added, try to look it up when adding schedules
|
||||||
|
- key: general.allow_unadded_airports
|
||||||
|
name: 'Allow unadded airports'
|
||||||
|
group: general
|
||||||
|
value: false
|
||||||
|
options:
|
||||||
|
type: boolean
|
||||||
|
description: If an un-added airport is used, it is looked up and added
|
||||||
- key: general.check_prerelease_version
|
- key: general.check_prerelease_version
|
||||||
name: 'Pre-release versions in version check'
|
name: 'Pre-release versions in version check'
|
||||||
group: general
|
group: general
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ use App\Events\UserStatsChanged;
|
|||||||
use App\Exceptions\AircraftInvalid;
|
use App\Exceptions\AircraftInvalid;
|
||||||
use App\Exceptions\AircraftNotAtAirport;
|
use App\Exceptions\AircraftNotAtAirport;
|
||||||
use App\Exceptions\AircraftPermissionDenied;
|
use App\Exceptions\AircraftPermissionDenied;
|
||||||
|
use App\Exceptions\AirportNotFound;
|
||||||
use App\Exceptions\PirepCancelNotAllowed;
|
use App\Exceptions\PirepCancelNotAllowed;
|
||||||
use App\Exceptions\UserNotAtAirport;
|
use App\Exceptions\UserNotAtAirport;
|
||||||
use App\Models\Acars;
|
use App\Models\Acars;
|
||||||
@@ -25,6 +26,7 @@ use App\Models\Pirep;
|
|||||||
use App\Models\PirepFieldValue;
|
use App\Models\PirepFieldValue;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Repositories\AircraftRepository;
|
use App\Repositories\AircraftRepository;
|
||||||
|
use App\Repositories\AirportRepository;
|
||||||
use App\Repositories\PirepRepository;
|
use App\Repositories\PirepRepository;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use function count;
|
use function count;
|
||||||
@@ -34,22 +36,33 @@ use Illuminate\Support\Facades\Log;
|
|||||||
class PirepService extends Service
|
class PirepService extends Service
|
||||||
{
|
{
|
||||||
private $aircraftRepo;
|
private $aircraftRepo;
|
||||||
|
private $airportRepo;
|
||||||
|
private $airportSvc;
|
||||||
private $geoSvc;
|
private $geoSvc;
|
||||||
private $userSvc;
|
|
||||||
private $pirepRepo;
|
private $pirepRepo;
|
||||||
|
private $userSvc;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param AircraftRepository $aircraftRepo
|
* @param AircraftRepository $aircraftRepo
|
||||||
* @param GeoService $geoSvc
|
* @param GeoService $geoSvc
|
||||||
* @param PirepRepository $pirepRepo
|
* @param PirepRepository $pirepRepo
|
||||||
* @param UserService $userSvc
|
* @param UserService $userSvc
|
||||||
|
* @param AirportRepository $airportRepo
|
||||||
|
* @param AirportService $airportSvc
|
||||||
|
* @param GeoService $geoSvc
|
||||||
|
* @param PirepRepository $pirepRepo
|
||||||
|
* @param UserService $userSvc
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
|
AirportRepository $airportRepo,
|
||||||
|
AirportService $airportSvc,
|
||||||
AircraftRepository $aircraftRepo,
|
AircraftRepository $aircraftRepo,
|
||||||
GeoService $geoSvc,
|
GeoService $geoSvc,
|
||||||
PirepRepository $pirepRepo,
|
PirepRepository $pirepRepo,
|
||||||
UserService $userSvc
|
UserService $userSvc
|
||||||
) {
|
) {
|
||||||
|
$this->airportRepo = $airportRepo;
|
||||||
|
$this->airportSvc = $airportSvc;
|
||||||
$this->aircraftRepo = $aircraftRepo;
|
$this->aircraftRepo = $aircraftRepo;
|
||||||
$this->geoSvc = $geoSvc;
|
$this->geoSvc = $geoSvc;
|
||||||
$this->userSvc = $userSvc;
|
$this->userSvc = $userSvc;
|
||||||
@@ -62,6 +75,7 @@ class PirepService extends Service
|
|||||||
* @param \App\Models\User $user
|
* @param \App\Models\User $user
|
||||||
* @param array $attrs
|
* @param array $attrs
|
||||||
*
|
*
|
||||||
|
* @throws AirportNotFound If one of the departure or arrival airports isn't found locally
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*
|
*
|
||||||
* @return \App\Models\Pirep
|
* @return \App\Models\Pirep
|
||||||
@@ -82,6 +96,23 @@ class PirepService extends Service
|
|||||||
|
|
||||||
$pirep = new Pirep($attrs);
|
$pirep = new Pirep($attrs);
|
||||||
|
|
||||||
|
// Check if the airports listed actually exist or not. If they're not in the local DB
|
||||||
|
// throw an error which should bubble up to say that they don't
|
||||||
|
if (setting('general.allow_unadded_airports', false) === true) {
|
||||||
|
$this->airportSvc->lookupAirportIfNotFound($pirep->dpt_airport_id);
|
||||||
|
$this->airportSvc->lookupAirportIfNotFound($pirep->arr_airport_id);
|
||||||
|
} else {
|
||||||
|
$dptApt = $this->airportRepo->findWithoutFail($pirep->dpt_airport_id);
|
||||||
|
if (!$dptApt) {
|
||||||
|
throw new AirportNotFound($pirep->dpt_airport_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
$arrApt = $this->airportRepo->findWithoutFail($pirep->arr_airport_id);
|
||||||
|
if (!$arrApt) {
|
||||||
|
throw new AirportNotFound($pirep->arr_airport_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// See if this user is at the current airport
|
// See if this user is at the current airport
|
||||||
/* @noinspection NotOptimalIfConditionsInspection */
|
/* @noinspection NotOptimalIfConditionsInspection */
|
||||||
if (setting('pilots.only_flights_from_current')
|
if (setting('pilots.only_flights_from_current')
|
||||||
|
|||||||
Reference in New Issue
Block a user