Cleanup SI Unit classes and interface for REST responses; fixes to a few METAR parsing issues
This commit is contained in:
@@ -3,11 +3,8 @@
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use App\Models\Enums\PirepStatus;
|
||||
use App\Support\Units\Distance;
|
||||
use App\Support\Units\Fuel;
|
||||
use Illuminate\Http\Resources\Json\Resource;
|
||||
|
||||
class Pirep extends Resource
|
||||
class Pirep extends Response
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
@@ -18,43 +15,36 @@ class Pirep extends Resource
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
$pirep = parent::toArray($request);
|
||||
$res = parent::toArray($request);
|
||||
$res['ident'] = $this->ident;
|
||||
|
||||
$pirep['ident'] = $this->ident;
|
||||
|
||||
if ($this->distance instanceof Distance) {
|
||||
$pirep['distance'] = $this->distance->units;
|
||||
}
|
||||
|
||||
if ($this->fuel_used instanceof Fuel) {
|
||||
$pirep['fuel_used'] = $this->fuel_used->units;
|
||||
}
|
||||
|
||||
if ($this->planned_distance instanceof Distance) {
|
||||
$pirep['planned_distance'] = $this->planned_distance->units;
|
||||
}
|
||||
$this->checkUnitFields($res, [
|
||||
'distance',
|
||||
'fuel_used',
|
||||
'planned_distance',
|
||||
]);
|
||||
|
||||
/*
|
||||
* Relationship fields
|
||||
*/
|
||||
|
||||
if ($this->block_on_time) {
|
||||
$pirep['block_on_time'] = $this->block_on_time->toIso8601ZuluString();
|
||||
$res['block_on_time'] = $this->block_on_time->toIso8601ZuluString();
|
||||
}
|
||||
|
||||
if ($this->block_off_time) {
|
||||
$pirep['block_off_time'] = $this->block_off_time->toIso8601ZuluString();
|
||||
$res['block_off_time'] = $this->block_off_time->toIso8601ZuluString();
|
||||
}
|
||||
|
||||
$pirep['status_text'] = PirepStatus::label($this->status);
|
||||
$res['status_text'] = PirepStatus::label($this->status);
|
||||
|
||||
$pirep['airline'] = new Airline($this->airline);
|
||||
$pirep['dpt_airport'] = new Airport($this->dpt_airport);
|
||||
$pirep['arr_airport'] = new Airport($this->arr_airport);
|
||||
$res['airline'] = new Airline($this->airline);
|
||||
$res['dpt_airport'] = new Airport($this->dpt_airport);
|
||||
$res['arr_airport'] = new Airport($this->arr_airport);
|
||||
|
||||
$pirep['position'] = new Acars($this->position);
|
||||
$pirep['comments'] = PirepComment::collection($this->comments);
|
||||
$pirep['user'] = [
|
||||
$res['position'] = new Acars($this->position);
|
||||
$res['comments'] = PirepComment::collection($this->comments);
|
||||
$res['user'] = [
|
||||
'id' => $this->user->id,
|
||||
'name' => $this->user->name,
|
||||
'home_airport_id' => $this->user->home_airport_id,
|
||||
@@ -62,8 +52,8 @@ class Pirep extends Resource
|
||||
];
|
||||
|
||||
// format to kvp
|
||||
$pirep['fields'] = new PirepFieldCollection($this->fields);
|
||||
$res['fields'] = new PirepFieldCollection($this->fields);
|
||||
|
||||
return $pirep;
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user