diff --git a/app/Http/Controllers/Api/PirepController.php b/app/Http/Controllers/Api/PirepController.php index 488b13d0..72a5dbfb 100644 --- a/app/Http/Controllers/Api/PirepController.php +++ b/app/Http/Controllers/Api/PirepController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers\Api; +use App\Http\Requests\Acars\UpdateRequest; use Auth; use Log; use Illuminate\Http\Request; @@ -114,6 +115,33 @@ class PirepController extends RestController 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 * @param $id diff --git a/app/Http/Requests/Acars/UpdateRequest.php b/app/Http/Requests/Acars/UpdateRequest.php new file mode 100644 index 00000000..f874e901 --- /dev/null +++ b/app/Http/Requests/Acars/UpdateRequest.php @@ -0,0 +1,50 @@ +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; + } +} diff --git a/app/Routes/api.php b/app/Routes/api.php index 87300ff0..8bf16b2d 100755 --- a/app/Routes/api.php +++ b/app/Routes/api.php @@ -24,9 +24,9 @@ Route::group([], function() Route::get('pireps/{pirep_id}', 'PirepController@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/geojson', 'PirepController@acars_geojson'); - Route::get('pireps/{pirep_id}/comments', 'PirepController@comments_get'); Route::get('status', 'StatusController@status'); Route::get('version', 'StatusController@status'); @@ -38,9 +38,14 @@ Route::group([], function() Route::group(['middleware' => ['api.auth']], function () { 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}/comments', 'PirepController@comments_post'); 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/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/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'); # This is the info of the user whose token is in use