diff --git a/app/Database/factories/AircraftFactory.php b/app/Database/factories/AircraftFactory.php index 19c6d7e7..a2bbefb8 100644 --- a/app/Database/factories/AircraftFactory.php +++ b/app/Database/factories/AircraftFactory.php @@ -1,24 +1,30 @@ define(App\Models\Aircraft::class, function (Faker $faker) { return [ 'id' => null, 'subfleet_id' => function () { - return factory(\App\Models\Subfleet::class)->create()->id; + return factory(Subfleet::class)->create()->id; }, 'airport_id' => function () { - return factory(\App\Models\Airport::class)->create()->id; + return factory(Airport::class)->create()->id; }, 'iata' => $faker->unique()->text(5), 'icao' => $faker->unique()->text(5), 'name' => $faker->text(50), 'registration' => $faker->unique()->text(10), - 'hex_code' => \App\Support\ICAO::createHexCode(), + 'hex_code' => ICAO::createHexCode(), + 'mtow' => $faker->randomFloat(2, 0, 50000), 'zfw' => $faker->randomFloat(2, 0, 50000), - 'status' => \App\Models\Enums\AircraftStatus::ACTIVE, - 'state' => \App\Models\Enums\AircraftState::PARKED, + 'status' => AircraftStatus::ACTIVE, + 'state' => AircraftState::PARKED, 'created_at' => $faker->dateTimeBetween('-1 week', 'now'), 'updated_at' => function (array $pirep) { return $pirep['created_at']; diff --git a/app/Database/migrations/2020_09_03_141152_aircraft_add_mtow.php b/app/Database/migrations/2020_09_03_141152_aircraft_add_mtow.php new file mode 100644 index 00000000..b5bb3714 --- /dev/null +++ b/app/Database/migrations/2020_09_03_141152_aircraft_add_mtow.php @@ -0,0 +1,33 @@ +unsignedDecimal('mtow') + ->nullable() + ->default(0.0) + ->after('hex_code'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('aircraft', function (Blueprint $table) { + $table->dropColumn('mtow'); + }); + } +} diff --git a/app/Models/Aircraft.php b/app/Models/Aircraft.php index faff4311..2994c6ee 100644 --- a/app/Models/Aircraft.php +++ b/app/Models/Aircraft.php @@ -16,6 +16,8 @@ use Carbon\Carbon; * @property string icao * @property string registration * @property int flight_time + * @property float mtow + * @property float zfw * @property string hex_code * @property Airport airport * @property Subfleet subfleet @@ -39,6 +41,7 @@ class Aircraft extends Model 'registration', 'hex_code', 'flight_time', + 'mtow', 'zfw', 'status', 'state', @@ -49,6 +52,7 @@ class Aircraft extends Model */ protected $casts = [ 'subfleet_id' => 'integer', + 'mtow' => 'float', 'zfw' => 'float', 'flight_time' => 'float', 'state' => 'integer', @@ -62,6 +66,8 @@ class Aircraft extends Model 'name' => 'required', 'status' => 'required', 'registration' => 'required', + 'mtow' => 'nullable|number', + 'zfw' => 'nullable|number', ]; /** diff --git a/resources/views/admin/aircraft/fields.blade.php b/resources/views/admin/aircraft/fields.blade.php index 33256981..e4ed4039 100644 --- a/resources/views/admin/aircraft/fields.blade.php +++ b/resources/views/admin/aircraft/fields.blade.php @@ -37,18 +37,15 @@
- - View list of - - IATA and ICAO Type Designators - - - -  Aircraft Information - + + View list of + IATA and ICAO Type Designators + +  Aircraft Information
+
{{ Form::label('name', 'Name:') }} * @@ -56,6 +53,7 @@

{{ $errors->first('name') }}

+
{{ Form::label('iata', 'IATA:') }} @@ -75,6 +73,20 @@

{{ $errors->first('registration') }}

+ +
+
+ {{ Form::label('mtow', 'Max Takeoff Weight (MTOW):') }} + {{ Form::text('mtow', null, ['class' => 'form-control']) }} +

{{ $errors->first('mtow') }}

+
+
+ {{ Form::label('zfw', 'Zero Fuel Weight (ZFW):') }} + {{ Form::text('zfw', null, ['class' => 'form-control']) }} +

{{ $errors->first('zfw') }}

+
+
+
diff --git a/tests/ApiTest.php b/tests/ApiTest.php index 1e46933d..cdbef75b 100644 --- a/tests/ApiTest.php +++ b/tests/ApiTest.php @@ -242,13 +242,17 @@ class ApiTest extends TestCase $fare_svc = app(FareService::class); + /** @var Subfleet $subfleet */ $subfleet = factory(Subfleet::class)->create([ 'airline_id' => $this->user->airline_id, ]); + /** @var Fare $fare */ $fare = factory(Fare::class)->create(); $fare_svc->setForSubfleet($subfleet, $fare); + + /** @var Aircraft $aircraft */ $aircraft = factory(Aircraft::class)->create([ 'subfleet_id' => $subfleet->id, ]); @@ -258,15 +262,27 @@ class ApiTest extends TestCase */ $resp = $this->get('/api/fleet/aircraft/'.$aircraft->id); $body = $resp->json()['data']; + $this->assertEquals($body['id'], $aircraft->id); + $this->assertEquals($body['name'], $aircraft->name); + $this->assertEquals($body['mtow'], $aircraft->mtow); + $this->assertEquals($body['zfw'], $aircraft->zfw); $resp = $this->get('/api/fleet/aircraft/'.$aircraft->id.'?registration='.$aircraft->registration); $body = $resp->json()['data']; + $this->assertEquals($body['id'], $aircraft->id); + $this->assertEquals($body['name'], $aircraft->name); + $this->assertEquals($body['mtow'], $aircraft->mtow); + $this->assertEquals($body['zfw'], $aircraft->zfw); $resp = $this->get('/api/fleet/aircraft/'.$aircraft->id.'?icao='.$aircraft->icao); $body = $resp->json()['data']; + $this->assertEquals($body['id'], $aircraft->id); + $this->assertEquals($body['name'], $aircraft->name); + $this->assertEquals($body['mtow'], $aircraft->mtow); + $this->assertEquals($body['zfw'], $aircraft->zfw); } public function testGetAllSettings()