SimBrief integration #405 (#635)

* SimBrief integration #405

* Add briefing as API response; add acars_xml field #405
This commit is contained in:
Nabeel S
2020-03-23 09:31:35 -04:00
committed by GitHub
parent 04b9e37e1d
commit 9e5386264f
70 changed files with 6816 additions and 192 deletions

View File

@@ -5,10 +5,8 @@ namespace App\Http\Controllers\Api;
use App\Contracts\Controller;
use App\Events\PirepPrefiled;
use App\Events\PirepUpdated;
use App\Exceptions\AircraftNotAtAirport;
use App\Exceptions\AircraftPermissionDenied;
use App\Exceptions\PirepCancelled;
use App\Exceptions\UserNotAtAirport;
use App\Http\Requests\Acars\CommentRequest;
use App\Http\Requests\Acars\FieldsRequest;
use App\Http\Requests\Acars\FileRequest;
@@ -22,7 +20,6 @@ use App\Http\Resources\PirepComment as PirepCommentResource;
use App\Http\Resources\PirepFieldCollection;
use App\Models\Acars;
use App\Models\Enums\AcarsType;
use App\Models\Enums\FlightType;
use App\Models\Enums\PirepFieldSource;
use App\Models\Enums\PirepSource;
use App\Models\Enums\PirepState;
@@ -113,7 +110,7 @@ class PirepController extends Controller
protected function checkCancelled(Pirep $pirep)
{
if ($pirep->cancelled) {
throw new PirepCancelled();
throw new PirepCancelled($pirep);
}
}
@@ -199,49 +196,9 @@ class PirepController extends Controller
$user = Auth::user();
$attrs = $this->parsePirep($request);
$attrs['user_id'] = $user->id;
$attrs['source'] = PirepSource::ACARS;
$attrs['state'] = PirepState::IN_PROGRESS;
if (!array_key_exists('status', $attrs)) {
$attrs['status'] = PirepStatus::INITIATED;
}
$pirep = new Pirep($attrs);
// See if this user is at the current airport
/* @noinspection NotOptimalIfConditionsInspection */
if (setting('pilots.only_flights_from_current')
&& $user->curr_airport_id !== $pirep->dpt_airport_id) {
throw new UserNotAtAirport($user, $pirep->dpt_airport);
}
// See if this user is allowed to fly this aircraft
if (setting('pireps.restrict_aircraft_to_rank', false)
&& !$this->userSvc->aircraftAllowed($user, $pirep->aircraft_id)) {
throw new AircraftPermissionDenied($user, $pirep->aircraft);
}
// See if this aircraft is at the departure airport
/* @noinspection NotOptimalIfConditionsInspection */
if (setting('pireps.only_aircraft_at_dpt_airport')
&& $pirep->aircraft_id !== $pirep->dpt_airport_id) {
throw new AircraftNotAtAirport($pirep->aircraft);
}
// Find if there's a duplicate, if so, let's work on that
$dupe_pirep = $this->pirepSvc->findDuplicate($pirep);
if ($dupe_pirep !== false) {
$pirep = $dupe_pirep;
$this->checkCancelled($pirep);
}
// Default to a scheduled passenger flight
if (!array_key_exists('flight_type', $attrs)) {
$attrs['flight_type'] = FlightType::SCHED_PAX;
}
$pirep->save();
$pirep = $this->pirepSvc->prefile($user, $attrs);
Log::info('PIREP PREFILED');
Log::info($pirep->id);