Update response objects

This commit is contained in:
Nabeel Shahzad
2020-03-31 17:26:55 -04:00
parent 819d3bcb47
commit d1d243ef06
4 changed files with 19 additions and 12 deletions

View File

@@ -119,11 +119,15 @@ class AcarsController extends Controller
public function acars_get($id, Request $request)
{
$this->pirepRepo->find($id);
$acars = Acars::with(['pirep'])
->where([
'pirep_id' => $id,
'type' => AcarsType::FLIGHT_PATH,
])
->orderBy('sim_time', 'asc')
->get();
return new AcarsRouteResource(Acars::where([
'pirep_id' => $id,
'type' => AcarsType::FLIGHT_PATH,
])->orderBy('sim_time', 'asc')->get());
return new AcarsRouteResource($acars);
}
/**

View File

@@ -6,6 +6,9 @@ use App\Contracts\Resource;
use App\Support\Units\Distance;
use App\Support\Units\Fuel;
/**
* @mixin \App\Models\Acars
*/
class Acars extends Resource
{
/**
@@ -31,6 +34,8 @@ class Acars extends Resource
$fuel = new Fuel($fuel, config('phpvms.internal_units.fuel'));
$res['fuel'] = $fuel->getResponseUnits();
$res['pirep'] = Pirep::make($this->whenLoaded('pirep'));
return $res;
}
}

View File

@@ -67,8 +67,8 @@ class Pirep extends Resource
$res['dpt_airport'] = new Airport($this->dpt_airport);
$res['arr_airport'] = new Airport($this->arr_airport);
$res['position'] = new Acars($this->position);
$res['comments'] = PirepComment::collection($this->comments);
$res['position'] = Acars::make($this->whenLoaded('position'));
$res['comments'] = PirepComment::make($this->whenLoaded('comments'));
$res['user'] = [
'id' => $this->user->id,
'name' => $this->user->name,

View File

@@ -8,16 +8,14 @@ use App\Support\Units\Distance;
use App\Support\Units\Fuel;
/**
* Class Acars
*
* @param string id
*
* @property string id
* @property string pirep_id
* @property int type
* @property string name
* @property float lat
* @property float lon
* @property float altitude
* @property float lat
* @property float lon
* @property float altitude
* @property int gs
* @property int heading
* @property int order