write the route if it hasn't been set by acars #184

This commit is contained in:
Nabeel Shahzad
2018-02-10 16:10:19 -06:00
parent 7a6b228d8f
commit 5a89b4f194
5 changed files with 18 additions and 7 deletions

View File

@@ -177,6 +177,7 @@ class PirepController extends RestController
* @return PirepResource
* @throws \Symfony\Component\HttpKernel\Exception\BadRequestHttpException
* @throws \Illuminate\Database\Eloquent\ModelNotFoundException
* @throws \Exception
*/
public function file($id, FileRequest $request)
{
@@ -198,6 +199,15 @@ class PirepController extends RestController
Log::error($e);
}
# See if there there is any route data posted
# If there isn't, then just write the route data from the
# route that's been posted from the PIREP
$w = ['pirep_id' => $pirep->id, 'type' => AcarsType::ROUTE];
$count = Acars::where($w)->count(['id']);
if($count === 0) {
$this->pirepSvc->saveRoute($pirep);
}
PirepResource::withoutWrapping();
return new PirepResource($pirep);
}

View File

@@ -102,6 +102,7 @@ class PIREPService extends BaseService
* Save the route into the ACARS table with AcarsType::ROUTE
* @param Pirep $pirep
* @return Pirep
* @throws \Exception
*/
public function saveRoute(Pirep $pirep): Pirep
{
@@ -111,13 +112,13 @@ class PIREPService extends BaseService
'type' => AcarsType::ROUTE,
])->delete();
# Delete the route
if (empty($pirep->route)) {
# See if a route exists
if (!filled($pirep->route)) {
return $pirep;
}
if(!$pirep->dpt_airport) {
Log::error('saveRoute: dpt_airport not found: '.$pirep->dpt_airport_id);
if (!filled($pirep->dpt_airport)) {
Log::error('saveRoute: dpt_airport not found: ' . $pirep->dpt_airport_id);
return $pirep;
}