Add order column to ACARS table for the order of the route points

This commit is contained in:
Nabeel Shahzad
2018-01-02 09:40:42 -06:00
parent 7a6395be27
commit 37cdde845d
5 changed files with 19 additions and 5 deletions

View File

@@ -18,6 +18,7 @@ class CreateAcarsTables extends Migration
$table->string('pirep_id', 12); $table->string('pirep_id', 12);
$table->unsignedTinyInteger('type'); $table->unsignedTinyInteger('type');
$table->unsignedInteger('nav_type')->nullable(); $table->unsignedInteger('nav_type')->nullable();
$table->unsignedInteger('order')->default(0);
$table->string('name')->nullable(); $table->string('name')->nullable();
$table->string('log')->nullable(); $table->string('log')->nullable();
$table->float('lat', 7, 4)->default(0.0); $table->float('lat', 7, 4)->default(0.0);

View File

@@ -15,6 +15,7 @@ class Acars extends BaseModel
'pirep_id', 'pirep_id',
'type', 'type',
'nav_type', 'nav_type',
'order',
'name', 'name',
'log', 'log',
'lat', 'lat',
@@ -31,6 +32,7 @@ class Acars extends BaseModel
public $casts = [ public $casts = [
'type' => 'integer', 'type' => 'integer',
'order' => 'integer',
'nav_type' => 'integer', 'nav_type' => 'integer',
'lat' => 'float', 'lat' => 'float',
'lon' => 'float', 'lon' => 'float',

View File

@@ -3,6 +3,7 @@
namespace App\Repositories; namespace App\Repositories;
use App\Models\Acars; use App\Models\Acars;
use App\Models\Enums\AcarsType;
use App\Models\Pirep; use App\Models\Pirep;
use App\Models\Enums\PirepState; use App\Models\Enums\PirepState;
@@ -27,7 +28,12 @@ class AcarsRepository extends BaseRepository //implements CacheableInterface
'type' => $type, 'type' => $type,
]; ];
return $this->orderBy('created_at', 'asc')->findWhere($where); $order_by = 'created_at';
if($type === AcarsType::ROUTE) {
$order_by = 'order';
}
return $this->orderBy('order', 'asc')->findWhere($where);
} }
/** /**

View File

@@ -62,9 +62,9 @@ class PIREPService extends BaseService
{ {
# Delete all the existing nav points # Delete all the existing nav points
Acars::where([ Acars::where([
'pirep_id' => $pirep->id, 'pirep_id' => $pirep->id,
'type' => AcarsType::ROUTE, 'type' => AcarsType::ROUTE,
])->delete(); ])->delete();
# Delete the route # Delete the route
if (empty($pirep->route)) { if (empty($pirep->route)) {
@@ -81,16 +81,19 @@ class PIREPService extends BaseService
/** /**
* @var $point Navdata * @var $point Navdata
*/ */
$point_count = 1;
foreach ($route as $point) { foreach ($route as $point) {
$acars = new Acars(); $acars = new Acars();
$acars->pirep_id = $pirep->id; $acars->pirep_id = $pirep->id;
$acars->type = AcarsType::ROUTE; $acars->type = AcarsType::ROUTE;
$acars->nav_type = $point->type; $acars->nav_type = $point->type;
$acars->order = $point_count;
$acars->name = $point->id; $acars->name = $point->id;
$acars->lat = $point->lat; $acars->lat = $point->lat;
$acars->lon = $point->lon; $acars->lon = $point->lon;
$acars->save(); $acars->save();
++$point_count;
} }
return $pirep; return $pirep;

View File

@@ -36,10 +36,12 @@ class PIREPTest extends TestCase
protected function getAcarsRoute($pirep) protected function getAcarsRoute($pirep)
{ {
$pirep->refresh();
$saved_route = []; $saved_route = [];
$route_points = Acars::where( $route_points = Acars::where(
['pirep_id' => $pirep->id, 'type' => AcarsType::ROUTE] ['pirep_id' => $pirep->id, 'type' => AcarsType::ROUTE]
)->orderBy('created_at', 'asc')->get(); )->orderBy('order', 'asc')->get();
foreach ($route_points as $point) { foreach ($route_points as $point) {
$saved_route[] = $point->name; $saved_route[] = $point->name;