Add a /api/pirep/{id}/update call

This commit is contained in:
Nabeel Shahzad 2018-01-30 11:36:22 -06:00
parent 9a426f79f9
commit c8ac739820
3 changed files with 84 additions and 6 deletions

View File

@ -2,6 +2,7 @@
namespace App\Http\Controllers\Api; namespace App\Http\Controllers\Api;
use App\Http\Requests\Acars\UpdateRequest;
use Auth; use Auth;
use Log; use Log;
use Illuminate\Http\Request; use Illuminate\Http\Request;
@ -114,6 +115,33 @@ class PirepController extends RestController
return new PirepResource($pirep); return new PirepResource($pirep);
} }
/**
* Create a new PIREP and place it in a "inprogress" and "prefile" state
* Once ACARS updates are being processed, then it can go into an 'ENROUTE'
* status, and whatever other statuses may be defined
*
* @param $id
* @param UpdateRequest $request
* @return PirepResource
* @throws \Symfony\Component\HttpKernel\Exception\BadRequestHttpException
* @throws \Prettus\Validator\Exceptions\ValidatorException
*/
public function update($id, UpdateRequest $request)
{
Log::info('PIREP Update, user ' . Auth::id(), $request->post());
$pirep = $this->pirepRepo->find($id);
$this->checkCancelled($pirep);
$attrs = $request->post();
$attrs['user_id'] = Auth::id();
$pirep = $this->pirepRepo->update($attrs, $id);
PirepResource::withoutWrapping();
return new PirepResource($pirep);
}
/** /**
* File the PIREP * File the PIREP
* @param $id * @param $id

View File

@ -0,0 +1,50 @@
<?php
namespace App\Http\Requests\Acars;
use Auth;
use App\Models\Pirep;
use Illuminate\Foundation\Http\FormRequest;
/**
* Class UpdateRequest
* @package App\Http\Requests\Acars
*/
class UpdateRequest extends FormRequest
{
public function authorize()
{
$pirep = Pirep::findOrFail($this->route('pirep_id'), ['user_id']);
return $pirep->user_id === Auth::id();
}
public function rules()
{
$rules = [
'airline_id' => 'nullable|exists:airlines,id',
'aircraft_id' => 'nullable|exists:aircraft,id',
'flight_id' => 'nullable|exists:flights,id',
'flight_number' => 'nullable',
'dpt_airport_id' => 'nullable',
'arr_airport_id' => 'nullable',
'route_code' => 'nullable',
'route_leg' => 'nullable',
'distance' => 'nullable|numeric',
'planned_distance' => 'nullable|numeric',
'planned_flight_time' => 'nullable|integer',
'flight_time' => 'nullable|integer',
'level' => 'nullable|numeric',
'zfw' => 'nullable|numeric',
'fuel_used' => 'nullable|numeric',
'block_fuel' => 'nullable|numeric',
'route' => 'nullable',
'notes' => 'nullable',
'source_name' => 'nullable|max:25',
'landing_rate' => 'nullable|numeric',
'flight_type' => 'nullable|integer',
'created_at' => 'nullable|date',
];
return $rules;
}
}

View File

@ -24,9 +24,9 @@ Route::group([], function()
Route::get('pireps/{pirep_id}', 'PirepController@get'); Route::get('pireps/{pirep_id}', 'PirepController@get');
Route::get('pireps/{pirep_id}/route', 'PirepController@route_get'); Route::get('pireps/{pirep_id}/route', 'PirepController@route_get');
Route::get('pireps/{pirep_id}/comments', 'PirepController@comments_get');
Route::get('pireps/{pirep_id}/acars/position', 'PirepController@acars_get'); Route::get('pireps/{pirep_id}/acars/position', 'PirepController@acars_get');
Route::get('pireps/{pirep_id}/acars/geojson', 'PirepController@acars_geojson'); Route::get('pireps/{pirep_id}/acars/geojson', 'PirepController@acars_geojson');
Route::get('pireps/{pirep_id}/comments', 'PirepController@comments_get');
Route::get('status', 'StatusController@status'); Route::get('status', 'StatusController@status');
Route::get('version', 'StatusController@status'); Route::get('version', 'StatusController@status');
@ -38,9 +38,14 @@ Route::group([], function()
Route::group(['middleware' => ['api.auth']], function () Route::group(['middleware' => ['api.auth']], function ()
{ {
Route::post('pireps/prefile', 'PirepController@prefile'); Route::post('pireps/prefile', 'PirepController@prefile');
Route::post('pireps/{pirep_id}/update', 'PirepController@update');
Route::post('pireps/{pirep_id}/file', 'PirepController@file'); Route::post('pireps/{pirep_id}/file', 'PirepController@file');
Route::post('pireps/{pirep_id}/comments', 'PirepController@comments_post');
Route::delete('pireps/{pirep_id}/cancel', 'PirepController@cancel'); Route::delete('pireps/{pirep_id}/cancel', 'PirepController@cancel');
Route::post('pireps/{pirep_id}/route', 'PirepController@route_post');
Route::delete('pireps/{pirep_id}/route', 'PirepController@route_delete');
Route::post('pireps/{pirep_id}/acars/position', 'PirepController@acars_store'); Route::post('pireps/{pirep_id}/acars/position', 'PirepController@acars_store');
Route::post('pireps/{pirep_id}/acars/positions', 'PirepController@acars_store'); Route::post('pireps/{pirep_id}/acars/positions', 'PirepController@acars_store');
@ -48,11 +53,6 @@ Route::group(['middleware' => ['api.auth']], function ()
Route::post('pireps/{pirep_id}/acars/log', 'PirepController@acars_log'); Route::post('pireps/{pirep_id}/acars/log', 'PirepController@acars_log');
Route::post('pireps/{pirep_id}/acars/logs', 'PirepController@acars_log'); Route::post('pireps/{pirep_id}/acars/logs', 'PirepController@acars_log');
Route::post('pireps/{pirep_id}/comments', 'PirepController@comments_post');
Route::post('pireps/{pirep_id}/route', 'PirepController@route_post');
Route::delete('pireps/{pirep_id}/route', 'PirepController@route_delete');
Route::get('settings', 'SettingsController@index'); Route::get('settings', 'SettingsController@index');
# This is the info of the user whose token is in use # This is the info of the user whose token is in use