cleanup PIREP api; file report via API
This commit is contained in:
@@ -11,7 +11,7 @@ use App\Facades\Utils;
|
|||||||
|
|
||||||
class AcarsReplay extends Command
|
class AcarsReplay extends Command
|
||||||
{
|
{
|
||||||
protected $signature = 'phpvms:replay {files} {--manual}';
|
protected $signature = 'phpvms:replay {files} {--manual} {--write-all}';
|
||||||
protected $description = 'Replay an ACARS file';
|
protected $description = 'Replay an ACARS file';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -67,6 +67,7 @@ class AcarsReplay extends Command
|
|||||||
$response = $this->httpClient->post('/api/pirep/prefile', [
|
$response = $this->httpClient->post('/api/pirep/prefile', [
|
||||||
'json' => [
|
'json' => [
|
||||||
'airline_id' => 1,
|
'airline_id' => 1,
|
||||||
|
'flight_number' => '6028',
|
||||||
'aircraft_id' => 1, # TODO: Lookup
|
'aircraft_id' => 1, # TODO: Lookup
|
||||||
'dpt_airport_id' => $flight->planned_depairport,
|
'dpt_airport_id' => $flight->planned_depairport,
|
||||||
'arr_airport_id' => $flight->planned_destairport,
|
'arr_airport_id' => $flight->planned_destairport,
|
||||||
@@ -80,9 +81,24 @@ class AcarsReplay extends Command
|
|||||||
return $body->id;
|
return $body->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mark the PIREP as filed
|
||||||
|
* @param $pirep_id
|
||||||
|
*/
|
||||||
|
protected function filePirep($pirep_id)
|
||||||
|
{
|
||||||
|
$response = $this->httpClient->post('/api/pirep/'.$pirep_id.'/file', [
|
||||||
|
'json'=> []
|
||||||
|
]);
|
||||||
|
|
||||||
|
$body = \json_decode($response->getBody()->getContents());
|
||||||
|
return $body;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $pirep_id
|
* @param $pirep_id
|
||||||
* @param $data
|
* @param $data
|
||||||
|
* @return array
|
||||||
*/
|
*/
|
||||||
protected function postUpdate($pirep_id, $data)
|
protected function postUpdate($pirep_id, $data)
|
||||||
{
|
{
|
||||||
@@ -100,9 +116,6 @@ class AcarsReplay extends Command
|
|||||||
|
|
||||||
$this->info("Update: $data->callsign, $upd[lat] x $upd[lon] \t\t"
|
$this->info("Update: $data->callsign, $upd[lat] x $upd[lon] \t\t"
|
||||||
. "hdg: $upd[heading]\t\talt: $upd[altitude]\t\tgs: $upd[gs]");
|
. "hdg: $upd[heading]\t\talt: $upd[altitude]\t\tgs: $upd[gs]");
|
||||||
/*$this->table([], [[
|
|
||||||
$data->callsign, $upd['lat'], $upd['lon'], $upd['heading'], $upd['altitude'], $upd['gs']
|
|
||||||
]]);*/
|
|
||||||
|
|
||||||
$response = $this->httpClient->post($uri, [
|
$response = $this->httpClient->post($uri, [
|
||||||
'json' => $upd
|
'json' => $upd
|
||||||
@@ -168,26 +181,26 @@ class AcarsReplay extends Command
|
|||||||
* Continue until we have no more flights and updates left
|
* Continue until we have no more flights and updates left
|
||||||
*/
|
*/
|
||||||
while ($flights->count() > 0) {
|
while ($flights->count() > 0) {
|
||||||
$updated_rows = [];
|
$flights = $flights->each(function ($updates, $idx) {
|
||||||
$flights = $flights->each(function ($updates, $idx)
|
|
||||||
{
|
|
||||||
$update = $updates->shift();
|
$update = $updates->shift();
|
||||||
$pirep_id = $this->pirepList[$update->callsign];
|
$pirep_id = $this->pirepList[$update->callsign];
|
||||||
|
|
||||||
$row = $this->postUpdate($pirep_id, $update);
|
$this->postUpdate($pirep_id, $update);
|
||||||
$updated_rows[] = $row;
|
|
||||||
|
# we're done
|
||||||
|
if($updates->count() === 0) {
|
||||||
|
$this->filePirep($pirep_id);
|
||||||
|
}
|
||||||
})->filter(function ($updates, $idx) {
|
})->filter(function ($updates, $idx) {
|
||||||
return $updates->count() > 0;
|
return $updates->count() > 0;
|
||||||
});
|
});
|
||||||
|
|
||||||
/*$this->table(
|
if(!$this->option('write-all')) {
|
||||||
['callsign', 'lat', 'lon', 'hdg', 'alt', 'gs'],
|
if (!$this->option('manual')) {
|
||||||
$updated_rows);*/
|
sleep($this->sleepTime);
|
||||||
|
} else {
|
||||||
if(!$this->option('manual')) {
|
$this->confirm('Send next batch of updates?', true);
|
||||||
sleep($this->sleepTime);
|
}
|
||||||
} else {
|
|
||||||
$this->confirm('Send next batch of updates?', true);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -202,10 +215,14 @@ class AcarsReplay extends Command
|
|||||||
$files = $this->argument('files');
|
$files = $this->argument('files');
|
||||||
$manual_mode = $this->option('manual');
|
$manual_mode = $this->option('manual');
|
||||||
|
|
||||||
if(!$manual_mode) {
|
if ($this->option('write-all')) {
|
||||||
$this->info('Going to send updates every 10s');
|
$this->info('In "dump-all" mode, just writing it all in');
|
||||||
} else {
|
} else {
|
||||||
$this->info('In "manual advance" mode');
|
if (!$manual_mode) {
|
||||||
|
$this->info('Going to send updates every 10s');
|
||||||
|
} else {
|
||||||
|
$this->info('In "manual advance" mode');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->runUpdates(explode(',', $files));
|
$this->runUpdates(explode(',', $files));
|
||||||
|
|||||||
+6
-114
@@ -1,4 +1,4 @@
|
|||||||
#
|
|
||||||
airlines:
|
airlines:
|
||||||
- id: 1
|
- id: 1
|
||||||
icao: VMS
|
icao: VMS
|
||||||
@@ -222,122 +222,14 @@ flights:
|
|||||||
updated_at: NOW
|
updated_at: NOW
|
||||||
- id: flightid_2
|
- id: flightid_2
|
||||||
airline_id: 1
|
airline_id: 1
|
||||||
flight_number: 101
|
flight_number: 6028
|
||||||
dpt_airport_id: KJFK
|
dpt_airport_id: KIAH
|
||||||
arr_airport_id: KAUS
|
arr_airport_id: KAUS
|
||||||
dpt_time: 9AM EST
|
dpt_time: 9AM CST
|
||||||
arr_time: 12PM CST
|
arr_time: 1030AM CST
|
||||||
route: KJFK KAUS
|
route: PITZZ4 MNURE WLEEE4
|
||||||
created_at: NOW
|
created_at: NOW
|
||||||
updated_at: NOW
|
updated_at: NOW
|
||||||
- id: flightid_3
|
|
||||||
airline_id: 1
|
|
||||||
flight_number: 200
|
|
||||||
dpt_airport_id: KJFK
|
|
||||||
arr_airport_id: KAUS
|
|
||||||
dpt_time: 9AM EST
|
|
||||||
arr_time: 12PM CST
|
|
||||||
route: KJFK KAUS
|
|
||||||
created_at: NOW
|
|
||||||
updated_at: NOW
|
|
||||||
- id: flightid_4
|
|
||||||
airline_id: 1
|
|
||||||
flight_number: 201
|
|
||||||
dpt_airport_id: KJFK
|
|
||||||
arr_airport_id: KAUS
|
|
||||||
dpt_time: 10AM EST
|
|
||||||
arr_time: 1PM CST
|
|
||||||
route: KJFK KAUS
|
|
||||||
created_at: NOW
|
|
||||||
updated_at: NOW
|
|
||||||
- id: flightid_5
|
|
||||||
airline_id: 1
|
|
||||||
flight_number: 202
|
|
||||||
dpt_airport_id: KJFK
|
|
||||||
arr_airport_id: KAUS
|
|
||||||
dpt_time: 11AM EST
|
|
||||||
arr_time: 2PM CST
|
|
||||||
route: KJFK KAUS
|
|
||||||
- id: flightid_6
|
|
||||||
airline_id: 1
|
|
||||||
flight_number: 203
|
|
||||||
dpt_airport_id: KJFK
|
|
||||||
arr_airport_id: KAUS
|
|
||||||
dpt_time: 12PM EST
|
|
||||||
arr_time: 3PM CST
|
|
||||||
route: KJFK KAUS
|
|
||||||
- id: flightid_7
|
|
||||||
airline_id: 1
|
|
||||||
flight_number: 204
|
|
||||||
dpt_airport_id: KJFK
|
|
||||||
arr_airport_id: KAUS
|
|
||||||
dpt_time: 1PM EST
|
|
||||||
arr_time: 4PM CST
|
|
||||||
route: KJFK KAUS
|
|
||||||
- id: flightid_8
|
|
||||||
airline_id: 1
|
|
||||||
flight_number: 205
|
|
||||||
dpt_airport_id: KJFK
|
|
||||||
arr_airport_id: KAUS
|
|
||||||
dpt_time: 2PM EST
|
|
||||||
arr_time: 5PM CST
|
|
||||||
route: KJFK KAUS
|
|
||||||
- id: flightid_9
|
|
||||||
airline_id: 1
|
|
||||||
flight_number: 206
|
|
||||||
dpt_airport_id: KJFK
|
|
||||||
arr_airport_id: KAUS
|
|
||||||
dpt_time: 3PM EST
|
|
||||||
arr_time: 6PM CST
|
|
||||||
route: KJFK KAUS
|
|
||||||
- id: flightid_10
|
|
||||||
airline_id: 1
|
|
||||||
flight_number: 207
|
|
||||||
dpt_airport_id: KJFK
|
|
||||||
arr_airport_id: KAUS
|
|
||||||
dpt_time: 4PM EST
|
|
||||||
arr_time: 7PM CST
|
|
||||||
route: KJFK KAUS
|
|
||||||
- id: flightid_11
|
|
||||||
airline_id: 1
|
|
||||||
flight_number: 208
|
|
||||||
dpt_airport_id: KJFK
|
|
||||||
arr_airport_id: KAUS
|
|
||||||
dpt_time: 5PM EST
|
|
||||||
arr_time: 8PM CST
|
|
||||||
route: KJFK KAUS
|
|
||||||
- id: flightid_12
|
|
||||||
airline_id: 1
|
|
||||||
flight_number: 209
|
|
||||||
dpt_airport_id: KJFK
|
|
||||||
arr_airport_id: KAUS
|
|
||||||
dpt_time: 6PM EST
|
|
||||||
arr_time: 9PM CST
|
|
||||||
route: KJFK KAUS
|
|
||||||
- id: flightid_13
|
|
||||||
airline_id: 1
|
|
||||||
flight_number: 210
|
|
||||||
dpt_airport_id: KJFK
|
|
||||||
arr_airport_id: KAUS
|
|
||||||
dpt_time: 7PM EST
|
|
||||||
arr_time: 10PM CST
|
|
||||||
route: KJFK KAUS
|
|
||||||
- id: flightid_14
|
|
||||||
airline_id: 1
|
|
||||||
flight_number: 211
|
|
||||||
dpt_airport_id: KJFK
|
|
||||||
arr_airport_id: KAUS
|
|
||||||
dpt_time: 8PM EST
|
|
||||||
arr_time: 11PM CST
|
|
||||||
route: KJFK KAUS
|
|
||||||
- id: flightid_15
|
|
||||||
airline_id: 1
|
|
||||||
flight_number: 212
|
|
||||||
dpt_airport_id: KJFK
|
|
||||||
arr_airport_id: KAUS
|
|
||||||
dpt_time: 9PM EST
|
|
||||||
arr_time: 12AM CST
|
|
||||||
route: KJFK KAUS
|
|
||||||
|
|
||||||
flight_fields:
|
flight_fields:
|
||||||
- id: 1
|
- id: 1
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ use App\Models\Enums\PirepStatus;
|
|||||||
use App\Http\Resources\Acars as AcarsResource;
|
use App\Http\Resources\Acars as AcarsResource;
|
||||||
use App\Http\Resources\Pirep as PirepResource;
|
use App\Http\Resources\Pirep as PirepResource;
|
||||||
|
|
||||||
|
use App\Services\PIREPService;
|
||||||
use App\Repositories\AcarsRepository;
|
use App\Repositories\AcarsRepository;
|
||||||
use App\Repositories\PirepRepository;
|
use App\Repositories\PirepRepository;
|
||||||
|
|
||||||
@@ -20,14 +20,16 @@ use App\Http\Controllers\AppBaseController;
|
|||||||
|
|
||||||
class PirepController extends AppBaseController
|
class PirepController extends AppBaseController
|
||||||
{
|
{
|
||||||
protected $acarsRepo, $pirepRepo;
|
protected $acarsRepo, $pirepRepo, $pirepSvc;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
AcarsRepository $acarsRepo,
|
AcarsRepository $acarsRepo,
|
||||||
PirepRepository $pirepRepo
|
PirepRepository $pirepRepo,
|
||||||
|
PIREPService $pirepSvc
|
||||||
) {
|
) {
|
||||||
$this->acarsRepo = $acarsRepo;
|
$this->acarsRepo = $acarsRepo;
|
||||||
$this->pirepRepo = $pirepRepo;
|
$this->pirepRepo = $pirepRepo;
|
||||||
|
$this->pirepSvc = $pirepSvc;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get($id)
|
public function get($id)
|
||||||
@@ -48,29 +50,37 @@ class PirepController extends AppBaseController
|
|||||||
Log::info('PIREP Prefile, user '. Auth::user()->pilot_id,
|
Log::info('PIREP Prefile, user '. Auth::user()->pilot_id,
|
||||||
$request->toArray());
|
$request->toArray());
|
||||||
|
|
||||||
/*$validator = Validator::make($request, [
|
$check_attrs = [
|
||||||
'aircraft_id' => 'required',
|
'airline_id',
|
||||||
'dpt_airport_id' => 'required',
|
'aircraft_id',
|
||||||
'arr_airport_id' => 'required',
|
'dpt_airport_id',
|
||||||
'altitude' => 'nullable|integer',
|
'arr_airport_id',
|
||||||
'route' => 'nullable',
|
'flight_id',
|
||||||
'notes' => 'nullable',
|
'flight_number',
|
||||||
]);*/
|
'route_leg',
|
||||||
|
'route_code',
|
||||||
|
'flight_time',
|
||||||
|
'planned_flight_time',
|
||||||
|
'altitude',
|
||||||
|
'route',
|
||||||
|
'notes',
|
||||||
|
];
|
||||||
|
|
||||||
$attr = [];
|
$attrs = [
|
||||||
$attr['user_id'] = Auth::user()->id;
|
'user_id' => Auth::user()->id,
|
||||||
$attr['airline_id'] = $request->get('airline_id');
|
];
|
||||||
$attr['aircraft_id'] = $request->get('aircraft_id');
|
|
||||||
$attr['dpt_airport_id'] = $request->get('dpt_airport_id');
|
foreach ($check_attrs as $attr) {
|
||||||
$attr['arr_airport_id'] = $request->get('arr_airport_id');
|
if ($request->filled($attr)) {
|
||||||
$attr['altitude'] = $request->get('altitude');
|
$attrs[$attr] = $request->get($attr);
|
||||||
$attr['route'] = $request->get('route');
|
}
|
||||||
$attr['notes'] = $request->get('notes');
|
}
|
||||||
$attr['state'] = PirepState::IN_PROGRESS;
|
|
||||||
$attr['status'] = PirepStatus::PREFILE;
|
$attrs['state'] = PirepState::IN_PROGRESS;
|
||||||
|
$attrs['status'] = PirepStatus::PREFILE;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$pirep = $this->pirepRepo->create($attr);
|
$pirep = $this->pirepRepo->create($attrs);
|
||||||
} catch(\Exception $e) {
|
} catch(\Exception $e) {
|
||||||
Log::error($e);
|
Log::error($e);
|
||||||
}
|
}
|
||||||
@@ -82,6 +92,58 @@ class PirepController extends AppBaseController
|
|||||||
return new PirepResource($pirep);
|
return new PirepResource($pirep);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* File the PIREP
|
||||||
|
* @param $id
|
||||||
|
* @param Request $request
|
||||||
|
* @return PirepResource
|
||||||
|
*/
|
||||||
|
public function file($id, Request $request)
|
||||||
|
{
|
||||||
|
Log::info('PIREP Prefile, user ' . Auth::user()->pilot_id,
|
||||||
|
$request->toArray());
|
||||||
|
|
||||||
|
$attrs = [];
|
||||||
|
$check_attrs = [
|
||||||
|
'airline_id',
|
||||||
|
'aircraft_id',
|
||||||
|
'dpt_airport_id',
|
||||||
|
'arr_airport_id',
|
||||||
|
'flight_id',
|
||||||
|
'flight_number',
|
||||||
|
'route_leg',
|
||||||
|
'route_code',
|
||||||
|
'flight_time',
|
||||||
|
'planned_flight_time',
|
||||||
|
'altitude',
|
||||||
|
'route',
|
||||||
|
'notes',
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach($check_attrs as $attr) {
|
||||||
|
if($request->filled($attr)) {
|
||||||
|
$attrs[$attr] = $request->get($attr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if($request->filled('fields')) {
|
||||||
|
$pirep_fields = $request->get('fields');
|
||||||
|
}
|
||||||
|
|
||||||
|
$attrs['state'] = PirepState::PENDING;
|
||||||
|
$attrs['status'] = PirepStatus::ARRIVED;
|
||||||
|
|
||||||
|
try {
|
||||||
|
$pirep = $this->pirepRepo->update($attrs, $id);
|
||||||
|
$pirep = $this->pirepSvc->create($pirep, $pirep_fields);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
Log::error($e);
|
||||||
|
}
|
||||||
|
|
||||||
|
PirepResource::withoutWrapping();
|
||||||
|
return new PirepResource($pirep);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all of the ACARS updates for a PIREP
|
* Get all of the ACARS updates for a PIREP
|
||||||
* @param $id
|
* @param $id
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ Route::group([], function ()
|
|||||||
|
|
||||||
Route::match(['get'], 'pirep/{id}', 'PirepController@get');
|
Route::match(['get'], 'pirep/{id}', 'PirepController@get');
|
||||||
Route::match(['post'], 'pirep/prefile', 'PirepController@prefile');
|
Route::match(['post'], 'pirep/prefile', 'PirepController@prefile');
|
||||||
|
Route::match(['post'], 'pirep/{id}/file', 'PirepController@file');
|
||||||
|
|
||||||
Route::match(['get'], 'pirep/{id}/acars', 'PirepController@acars_get');
|
Route::match(['get'], 'pirep/{id}/acars', 'PirepController@acars_get');
|
||||||
Route::match(['post'], 'pirep/{id}/acars', 'PirepController@acars_store');
|
Route::match(['post'], 'pirep/{id}/acars', 'PirepController@acars_store');
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ return [
|
|||||||
'accepted' => 'Accepted',
|
'accepted' => 'Accepted',
|
||||||
'pending' => 'Pending',
|
'pending' => 'Pending',
|
||||||
'rejected' => 'Rejected',
|
'rejected' => 'Rejected',
|
||||||
|
'in_progress' => 'In Progress',
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -14,12 +14,15 @@
|
|||||||
</h5>
|
</h5>
|
||||||
<div>
|
<div>
|
||||||
@if($pirep->state == PirepState::PENDING)
|
@if($pirep->state == PirepState::PENDING)
|
||||||
<div class="badge badge-warning">Pending</div>
|
<div class="badge badge-warning">
|
||||||
@elseif($pirep->state == PirepState::ACCEPTED)
|
@elseif($pirep->state == PirepState::ACCEPTED)
|
||||||
<div class="badge badge-success">Accepted</div>
|
<div class="badge badge-success">
|
||||||
|
@elseif($pirep->state == PirepState::REJECTED)
|
||||||
|
<div class="badge badge-danger">
|
||||||
@else
|
@else
|
||||||
<div class="badge badge-danger">Rejected</div>
|
<div class="badge badge-info">
|
||||||
@endif
|
@endif
|
||||||
|
{!! PirepState::label($pirep->state) !!}</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-sm-10">
|
<div class="col-sm-10">
|
||||||
|
|||||||
Reference in New Issue
Block a user