Add separate ACARS route to post log messages to the ACARS table

This commit is contained in:
Nabeel Shahzad 2018-01-03 22:16:18 -06:00
parent 81650f5c34
commit 8810f03c29
2 changed files with 37 additions and 1 deletions

View File

@ -229,4 +229,38 @@ class PirepController extends AppBaseController
AcarsResource::withoutWrapping(); AcarsResource::withoutWrapping();
return new AcarsResource($update); return new AcarsResource($update);
} }
/**
* Post ACARS LOG update for a PIREP. These updates won't show up on the map
* But rather in a log file.
* @param $id
* @param Request $request
* @return AcarsResource
* @throws \Symfony\Component\HttpKernel\Exception\BadRequestHttpException
*/
public function acars_log($id, Request $request)
{
$pirep = $this->pirepRepo->find($id);
# Check if the status is cancelled...
if ($pirep->state === PirepState::CANCELLED) {
throw new BadRequestHttpException('PIREP has been cancelled, updates can\'t be posted');
}
Log::info('Posting ACARS update', $request->toArray());
$attrs = $request->toArray();
$attrs['pirep_id'] = $id;
$attrs['type'] = AcarsType::LOG;
$update = Acars::create($attrs);
$update->save();
# Change the PIREP status
$pirep->status = PirepStatus::ENROUTE;
$pirep->save();
AcarsResource::withoutWrapping();
return new AcarsResource($update);
}
} }

View File

@ -25,11 +25,13 @@ Route::group([], function()
Route::group(['middleware' => ['api.auth']], function () Route::group(['middleware' => ['api.auth']], function ()
{ {
Route::get('pireps/{id}', 'PirepController@get'); Route::get('pireps/{id}', 'PirepController@get');
Route::post('pireps/prefile', 'PirepController@prefile'); Route::post('pireps/prefile', 'PirepController@prefile');
Route::post('pireps/{id}/file', 'PirepController@file'); Route::post('pireps/{id}/file', 'PirepController@file');
Route::post('pireps/{id}/cancel', 'PirepController@cancel'); Route::post('pireps/{id}/cancel', 'PirepController@cancel');
Route::post('pireps/{id}/acars', 'PirepController@acars_store'); Route::post('pireps/{id}/acars', 'PirepController@acars_store');
Route::post('pireps/{id}/acars/position', 'PirepController@acars_store');
Route::post('pireps/{id}/acars/log', 'PirepController@acars_log');
# This is the info of the user whose token is in use # This is the info of the user whose token is in use
Route::get('user', 'UserController@index'); Route::get('user', 'UserController@index');