Add order column to ACARS table for the order of the route points
This commit is contained in:
@@ -18,6 +18,7 @@ class CreateAcarsTables extends Migration
|
||||
$table->string('pirep_id', 12);
|
||||
$table->unsignedTinyInteger('type');
|
||||
$table->unsignedInteger('nav_type')->nullable();
|
||||
$table->unsignedInteger('order')->default(0);
|
||||
$table->string('name')->nullable();
|
||||
$table->string('log')->nullable();
|
||||
$table->float('lat', 7, 4)->default(0.0);
|
||||
|
||||
@@ -15,6 +15,7 @@ class Acars extends BaseModel
|
||||
'pirep_id',
|
||||
'type',
|
||||
'nav_type',
|
||||
'order',
|
||||
'name',
|
||||
'log',
|
||||
'lat',
|
||||
@@ -31,6 +32,7 @@ class Acars extends BaseModel
|
||||
|
||||
public $casts = [
|
||||
'type' => 'integer',
|
||||
'order' => 'integer',
|
||||
'nav_type' => 'integer',
|
||||
'lat' => 'float',
|
||||
'lon' => 'float',
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Repositories;
|
||||
|
||||
use App\Models\Acars;
|
||||
use App\Models\Enums\AcarsType;
|
||||
use App\Models\Pirep;
|
||||
use App\Models\Enums\PirepState;
|
||||
|
||||
@@ -27,7 +28,12 @@ class AcarsRepository extends BaseRepository //implements CacheableInterface
|
||||
'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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -62,9 +62,9 @@ class PIREPService extends BaseService
|
||||
{
|
||||
# Delete all the existing nav points
|
||||
Acars::where([
|
||||
'pirep_id' => $pirep->id,
|
||||
'type' => AcarsType::ROUTE,
|
||||
])->delete();
|
||||
'pirep_id' => $pirep->id,
|
||||
'type' => AcarsType::ROUTE,
|
||||
])->delete();
|
||||
|
||||
# Delete the route
|
||||
if (empty($pirep->route)) {
|
||||
@@ -81,16 +81,19 @@ class PIREPService extends BaseService
|
||||
/**
|
||||
* @var $point Navdata
|
||||
*/
|
||||
$point_count = 1;
|
||||
foreach ($route as $point) {
|
||||
$acars = new Acars();
|
||||
$acars->pirep_id = $pirep->id;
|
||||
$acars->type = AcarsType::ROUTE;
|
||||
$acars->nav_type = $point->type;
|
||||
$acars->order = $point_count;
|
||||
$acars->name = $point->id;
|
||||
$acars->lat = $point->lat;
|
||||
$acars->lon = $point->lon;
|
||||
|
||||
$acars->save();
|
||||
++$point_count;
|
||||
}
|
||||
|
||||
return $pirep;
|
||||
|
||||
@@ -36,10 +36,12 @@ class PIREPTest extends TestCase
|
||||
|
||||
protected function getAcarsRoute($pirep)
|
||||
{
|
||||
$pirep->refresh();
|
||||
|
||||
$saved_route = [];
|
||||
$route_points = Acars::where(
|
||||
['pirep_id' => $pirep->id, 'type' => AcarsType::ROUTE]
|
||||
)->orderBy('created_at', 'asc')->get();
|
||||
)->orderBy('order', 'asc')->get();
|
||||
|
||||
foreach ($route_points as $point) {
|
||||
$saved_route[] = $point->name;
|
||||
|
||||
Reference in New Issue
Block a user