Skip to content

Commit

Permalink
Merge branch 'dev' into bug-fix-nabeelio#1275
Browse files Browse the repository at this point in the history
  • Loading branch information
nabeelio committed Aug 23, 2023
2 parents 5404840 + 58dcb45 commit 122f899
Show file tree
Hide file tree
Showing 101 changed files with 1,491 additions and 210 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,20 @@
return new class() extends Migration {
public function up()
{
Schema::table('pirep_fares', function (Blueprint $table) {
$table->unsignedBigInteger('fare_id')->nullable()->change();
$table->string('code')->nullable();
$table->string('name')->nullable();
$table->unsignedDecimal('price')->nullable()->default(0.00);
$table->unsignedDecimal('cost')->nullable()->default(0.00);
$table->unsignedInteger('capacity')->nullable()->default(0);
$table->unsignedTinyInteger('type')
->default(FareType::PASSENGER)
->nullable()
->after('capacity');
});
if (!Schema::hasColumns('pirep_fares', ['code', 'name'])) {
Schema::table('pirep_fares', function (Blueprint $table) {
$table->unsignedBigInteger('fare_id')->nullable()->change();
$table->string('code')->nullable();
$table->string('name')->nullable();
$table->unsignedDecimal('price')->nullable()->default(0.00);
$table->unsignedDecimal('cost')->nullable()->default(0.00);
$table->unsignedInteger('capacity')->nullable()->default(0);
$table->unsignedTinyInteger('type')
->default(FareType::PASSENGER)
->nullable()
->after('capacity');
});
}

/**
* Update all of the existing PIREP fares to include the existing fare info
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

use App\Models\User;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class() extends Migration {
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('users', function (Blueprint $table) {
$table->timestamp('email_verified_at')->nullable();
});

User::where('email_verified_at', null)->update(['email_verified_at' => now()]);
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class() extends Migration {
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('bids', function (Blueprint $table) {
$table->unsignedInteger('aircraft_id')->nullable()->after('flight_id');
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('bids', function (Blueprint $table) {
$table->dropColumn('aircraft_id');
});
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

// Add events table and update flights & pirep tables for references
return new class() extends Migration {
public function up()
{
// Create events table
if (!Schema::hasTable('migrations_data')) {
Schema::create('migrations_data', function (Blueprint $table) {
$table->increments('id');
$table->string('migration', 191);
$table->integer('batch');
});
}
}
};
9 changes: 8 additions & 1 deletion app/Database/seeds/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,13 @@
options: ''
type: boolean
description: 'Whether or not someone can bid on multiple flights'
- key: bids.block_aircraft
name: 'Restrict Aircraft'
group: bids
value: true
options: ''
type: boolean
description: 'When enabled, an aircraft can only be used for one active Bid and Flight/Pirep'
- key: bids.expire_time
name: 'Expire Time'
group: bids
Expand Down Expand Up @@ -485,4 +492,4 @@
value: true
options: ''
type: boolean
description: Send out a discord notification when a user's rank is changed
description: Send out a discord notification when a user's rank is changed
43 changes: 43 additions & 0 deletions app/Exceptions/BidExistsForAircraft.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace App\Exceptions;

use App\Models\Aircraft;

class BidExistsForAircraft extends AbstractHttpException
{
public function __construct(
private readonly Aircraft $aircraft
) {
parent::__construct(
409,
'A bid already exists for this aircraft'
);
}

/**
* Return the RFC 7807 error type (without the URL root)
*/
public function getErrorType(): string
{
return 'bid-exists';
}

/**
* Get the detailed error string
*/
public function getErrorDetails(): string
{
return $this->getMessage();
}

/**
* Return an array with the error details, merged with the RFC7807 response
*/
public function getErrorMetadata(): array
{
return [
'aircraft_id' => $this->aircraft->id,
];
}
}
22 changes: 17 additions & 5 deletions app/Http/Controllers/Admin/AircraftController.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ public function index(Request $request): View
public function create(Request $request): View
{
return view('admin.aircraft.create', [
'airports' => $this->airportRepo->selectBoxList(),
'hubs' => $this->airportRepo->selectBoxList(true, true),
'airports' => [],
'hubs' => [],
'subfleets' => Subfleet::all()->pluck('name', 'id'),
'statuses' => AircraftStatus::select(false),
'subfleet_id' => $request->query('subfleet'),
Expand Down Expand Up @@ -130,17 +130,29 @@ public function show($id): View
*/
public function edit(int $id): View|RedirectResponse
{
$aircraft = $this->aircraftRepo->findWithoutFail($id);
/** @var Aircraft $aircraft */
$aircraft = $this->aircraftRepo
->with(['airport', 'hub'])
->findWithoutFail($id);

if (empty($aircraft)) {
Flash::error('Aircraft not found');
return redirect(route('admin.aircraft.index'));
}

$airports = ['' => ''];
if ($aircraft->airport) {
$airports[$aircraft->airport->id] = $aircraft->airport->description;
}

if ($aircraft->hub) {
$airports[$aircraft->hub->id] = $aircraft->hub->description;
}

return view('admin.aircraft.edit', [
'aircraft' => $aircraft,
'airports' => $this->airportRepo->selectBoxList(),
'hubs' => $this->airportRepo->selectBoxList(true, true),
'airports' => $airports,
'hubs' => $airports,
'subfleets' => Subfleet::all()->pluck('name', 'id'),
'statuses' => AircraftStatus::select(false),
]);
Expand Down
27 changes: 20 additions & 7 deletions app/Http/Controllers/Admin/FlightController.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public function index(Request $request): View
return view('admin.flights.index', [
'flights' => $flights,
'airlines' => $this->airlineRepo->selectBoxList(true),
'airports' => $this->airportRepo->selectBoxList(true),
'airports' => [],
]);
}

Expand All @@ -139,8 +139,8 @@ public function create(): View
'days' => 0,
'flight_fields' => $this->flightFieldRepo->all(),
'airlines' => $this->airlineRepo->selectBoxList(),
'airports' => $this->airportRepo->selectBoxList(true, false),
'alt_airports' => $this->airportRepo->selectBoxList(true),
'airports' => [],
'alt_airports' => [],
'flight_types' => FlightType::select(false),
]);
}
Expand Down Expand Up @@ -196,13 +196,26 @@ public function show(string $id): RedirectResponse|View
*/
public function edit(string $id): RedirectResponse|View
{
$flight = $this->flightRepo->findWithoutFail($id);
/** @var Flight $flight */
$flight = $this->flightRepo
->with(['dpt_airport', 'arr_airport', 'alt_airport'])
->findWithoutFail($id);

if (empty($flight)) {
Flash::error('Flight not found');

return redirect(route('admin.flights.index'));
}

$airports = [
['' => ''],
[$flight->arr_airport->id => $flight->arr_airport->full_name],
[$flight->dpt_airport->id => $flight->dpt_airport->full_name],
];

if ($flight->alt_airport) {
$airports[] = [$flight->alt_airport->id => $flight->alt_airport->full_name];
}

$time = new Time($flight->flight_time);

$flight->hours = $time->hours;
Expand All @@ -213,8 +226,8 @@ public function edit(string $id): RedirectResponse|View
'days' => $flight->days,
'flight_fields' => $this->flightFieldRepo->all(),
'airlines' => $this->airlineRepo->selectBoxList(),
'airports' => $this->airportRepo->selectBoxList(),
'alt_airports' => $this->airportRepo->selectBoxList(true),
'airports' => $airports,
'alt_airports' => $airports,
'avail_fares' => $this->getAvailFares($flight),
'avail_subfleets' => $this->getAvailSubfleets($flight),
'flight_types' => FlightType::select(true),
Expand Down
19 changes: 16 additions & 3 deletions app/Http/Controllers/Admin/PirepController.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public function create(): View
{
return view('admin.pireps.create', [
'aircraft' => $this->aircraftList(),
'airports' => $this->airportRepo->selectBoxList(),
'airports' => [],
'airlines' => $this->airlineRepo->selectBoxList(),
]);
}
Expand Down Expand Up @@ -276,7 +276,10 @@ public function show(string $id): RedirectResponse|View
*/
public function edit(string $id): RedirectResponse|View
{
$pirep = $this->pirepRepo->findWithoutFail($id);
$pirep = $this->pirepRepo
->with(['dpt_airport', 'arr_airport', 'alt_airport'])
->findWithoutFail($id);

if (empty($pirep)) {
Flash::error('Pirep not found');
return redirect(route('admin.pireps.index'));
Expand All @@ -300,11 +303,21 @@ public function edit(string $id): RedirectResponse|View

$journal = $this->journalRepo->getAllForObject($pirep, $pirep->airline->journal);

$airports = [
['' => ''],
[$pirep->arr_airport->id => $pirep->arr_airport->full_name],
[$pirep->dpt_airport->id => $pirep->dpt_airport->full_name],
];

if ($pirep->alt_airport) {
$airports[] = [$pirep->alt_airport->id => $pirep->alt_airport->full_name];
}

return view('admin.pireps.edit', [
'pirep' => $pirep,
'aircraft' => $pirep->aircraft,
'aircraft_list' => $this->aircraftList(),
'airports_list' => $this->airportRepo->selectBoxList(),
'airports_list' => $airports,
'airlines_list' => $this->airlineRepo->selectBoxList(),
'journal' => $journal,
]);
Expand Down
11 changes: 9 additions & 2 deletions app/Http/Controllers/Admin/SubfleetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public function create(): View
{
return view('admin.subfleets.create', [
'airlines' => Airline::all()->pluck('name', 'id'),
'airports' => [],
'hubs' => Airport::where('hub', 1)->pluck('name', 'id'),
'fuel_types' => FuelType::labels(),
]);
Expand Down Expand Up @@ -144,8 +145,9 @@ public function show(int $id): RedirectResponse|View
*/
public function edit(int $id): RedirectResponse|View
{
/** @var Subfleet $subfleet */
$subfleet = $this->subfleetRepo
->with(['fares', 'ranks', 'typeratings'])
->with(['home', 'fares', 'ranks', 'typeratings'])
->findWithoutFail($id);

if (empty($subfleet)) {
Expand All @@ -158,9 +160,14 @@ public function edit(int $id): RedirectResponse|View
$avail_ranks = $this->getAvailRanks($subfleet);
$avail_ratings = $this->getAvailTypeRatings($subfleet);

$airports = [];
if ($subfleet->home) {
$airports[$subfleet->home->id] = $subfleet->home->description;
}

return view('admin.subfleets.edit', [
'airlines' => Airline::all()->pluck('name', 'id'),
'hubs' => Airport::where('hub', 1)->pluck('name', 'id'),
'airports' => $airports,
'fuel_types' => FuelType::labels(),
'avail_fares' => $avail_fares,
'avail_ranks' => $avail_ranks,
Expand Down
16 changes: 12 additions & 4 deletions app/Http/Controllers/Admin/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ public function index(Request $request): View
public function create(): View
{
$airlines = $this->airlineRepo->selectBoxList();
$airports = $this->airportRepo->selectBoxList(false);
$countries = collect((new ISO3166())->all())
->mapWithKeys(fn ($item, $key) => [strtolower($item['alpha2']) => $item['name']]);
$roles = $this->roleRepo->selectBoxList(false, true);
Expand All @@ -92,7 +91,7 @@ public function create(): View
'timezones' => Timezonelist::toArray(),
'country' => new ISO3166(),
'countries' => $countries,
'airports' => $airports,
'airports' => [],
'ranks' => Rank::all()->pluck('name', 'id'),
'roles' => $roles,
]);
Expand Down Expand Up @@ -141,8 +140,9 @@ public function show(int $id): View
*/
public function edit(int $id): View
{
/** @var User $user */
$user = $this->userRepo
->with(['awards', 'fields', 'rank', 'typeratings'])
->with(['awards', 'fields', 'rank', 'typeratings', 'home_airport', 'location'])
->findWithoutFail($id);

if (empty($user)) {
Expand All @@ -158,10 +158,18 @@ public function edit(int $id): View
->mapWithKeys(fn ($item, $key) => [strtolower($item['alpha2']) => $item['name']]);

$airlines = $this->airlineRepo->selectBoxList();
$airports = $this->airportRepo->selectBoxList(false);
$roles = $this->roleRepo->selectBoxList(false, true);
$avail_ratings = $this->getAvailTypeRatings($user);

$airports = ['' => ''];
if ($user->home_airport) {
$airports[$user->home_airport->id] = $user->home_airport->description;
}

if ($user->location) {
$airports[$user->location->id] = $user->location->description;
}

return view('admin.users.edit', [
'user' => $user,
'pireps' => $pireps,
Expand Down
Loading

0 comments on commit 122f899

Please sign in to comment.