Skip to content

Commit

Permalink
Merge branch 'dev' into squashMigrations
Browse files Browse the repository at this point in the history
  • Loading branch information
nabeelio authored Jul 2, 2024
2 parents ee022bc + 7e037ec commit c70740c
Show file tree
Hide file tree
Showing 41 changed files with 717 additions and 138 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ docker-test:
-u $(shell id -u):$(shell id -g) \
-v $(shell pwd):/var/www/html \
-w /var/www/html \
laravelsail/php82-composer:latest \
laravelsail/php83-composer:latest \
composer install --ignore-platform-reqs
@vendor/bin/sail up

Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ docker run --rm \
-u "$(id -u):$(id -g)" \
-v "$(pwd):/var/www/html" \
-w /var/www/html \
laravelsail/php82-composer:latest \
laravelsail/php83-composer:latest \
composer install --ignore-platform-reqs

# Then you can start sail
Expand Down Expand Up @@ -75,6 +75,8 @@ sail composer install
sail npm run dev
```

To interact with databases (MariaDB, Redis...), please refer to the Laravel Sail documentation

### Building JS/CSS assets

Yarn is required, run:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

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

return new class() extends Migration {
public function up(): void
{
Schema::table('users', function (Blueprint $table) {
$table->string('vatsim_id')->default('')->after('discord_private_channel_id');
});
}

public function down(): void
{
Schema::table('users', function (Blueprint $table) {
$table->dropColumn('vatsim_id');
});
}
};
27 changes: 27 additions & 0 deletions app/Database/migrations/2024_06_03_124335_add_ivao_id_to_users.php
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('users', function (Blueprint $table) {
$table->string('ivao_id')->default('')->after('discord_private_channel_id');
});
}

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

use App\Contracts\Migration;
use App\Models\Expense;

/**
* Update the expenses to add the airline ID
*/
return new class() extends Migration {
public function up(): void
{
/** @var Expense[] $all_expenses */
$all_expenses = Expense::all();
foreach ($all_expenses as $expense) {
$this->getAirlineId($expense);
}
}

/**
* Figure out the airline ID
*
* @param Expense $expense
*
* @return void
*/
public function getAirlineId(Expense $expense): void
{
$klass = 'Expense';
if ($expense->ref_model) {
$ref = explode('\\', $expense->ref_model);
$klass = end($ref);
$obj = $expense->getReferencedObject();
}

if (empty($obj)) {
return;
}

if ($klass === 'Airport') {
// TODO: Get an airline ID?
} elseif ($klass === 'Subfleet') {
$expense->airline_id = $obj->airline_id;
} elseif ($klass === 'Aircraft') {
$expense->airline_id = $obj->airline->id;
}

$expense->save();
}
};
14 changes: 14 additions & 0 deletions app/Events/NewsUpdated.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace App\Events;

use App\Contracts\Event;
use App\Models\News;

class NewsUpdated extends Event
{
public function __construct(
public News $news
) {
}
}
2 changes: 1 addition & 1 deletion app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function render($request, Throwable $exception)
*/
private function handleApiError($request, Throwable $exception)
{
Log::error('API Error', $exception->getTrace());
Log::error('API Error: '.$exception->getMessage(), $exception->getTrace());

if ($exception instanceof AbstractHttpException) {
return $exception->getResponse();
Expand Down
22 changes: 9 additions & 13 deletions app/Http/Controllers/Admin/AircraftController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use App\Repositories\AirportRepository;
use App\Services\ExportService;
use App\Services\FileService;
use App\Services\FinanceService;
use App\Services\ImportService;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
Expand All @@ -26,19 +27,12 @@ class AircraftController extends Controller
{
use Importable;

/**
* AircraftController constructor.
*
* @param AirportRepository $airportRepo
* @param AircraftRepository $aircraftRepo
* @param FileService $fileSvc
* @param ImportService $importSvc
*/
public function __construct(
private readonly AirportRepository $airportRepo,
private readonly AircraftRepository $aircraftRepo,
private readonly FileService $fileSvc,
private readonly ImportService $importSvc,
private readonly FinanceService $financeSvc,
) {
}

Expand Down Expand Up @@ -317,7 +311,8 @@ protected function return_expenses_view(Aircraft $aircraft): View
*/
public function expenses(int $id, Request $request): View
{
$aircraft = $this->aircraftRepo->findWithoutFail($id);
/** @var Aircraft $aircraft */
$aircraft = $this->aircraftRepo->with('airline')->findWithoutFail($id);
if (empty($aircraft)) {
return $this->return_expenses_view($aircraft);
}
Expand All @@ -327,10 +322,11 @@ public function expenses(int $id, Request $request): View
}

if ($request->isMethod('post')) {
$expense = new Expense($request->post());
$expense->ref_model = Aircraft::class;
$expense->ref_model_id = $aircraft->id;
$expense->save();
$this->financeSvc->addExpense(
$request->post(),
$aircraft,
$aircraft->airline->id
);
} elseif ($request->isMethod('put')) {
$expense = Expense::findOrFail($request->input('expense_id'));
$expense->{$request->name} = $request->value;
Expand Down
15 changes: 6 additions & 9 deletions app/Http/Controllers/Admin/AirportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use App\Repositories\Criteria\WhereCriteria;
use App\Services\ExportService;
use App\Services\FileService;
use App\Services\FinanceService;
use App\Services\ImportService;
use App\Support\Timezonelist;
use Illuminate\Http\RedirectResponse;
Expand All @@ -25,15 +26,11 @@ class AirportController extends Controller
{
use Importable;

/**
* @param AirportRepository $airportRepo
* @param FileService $fileSvc
* @param ImportService $importSvc
*/
public function __construct(
private readonly AirportRepository $airportRepo,
private readonly FileService $fileSvc,
private readonly ImportService $importSvc,
private readonly FinanceService $financeSvc,
) {
}

Expand Down Expand Up @@ -270,10 +267,10 @@ public function expenses(string $id, Request $request): View
}

if ($request->isMethod('post')) {
$expense = new Expense($request->post());
$expense->ref_model = Airport::class;
$expense->ref_model_id = $airport->id;
$expense->save();
$this->financeSvc->addExpense(
$request->post(),
$airport,
);
} elseif ($request->isMethod('put')) {
$expense = Expense::findOrFail($request->input('expense_id'));
$expense->{$request->name} = $request->value;
Expand Down
5 changes: 5 additions & 0 deletions app/Http/Controllers/Admin/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ public function news(Request $request): View
$attrs['user_id'] = Auth::user()->id;

$this->newsSvc->addNews($attrs);
} elseif ($request->isMethod('patch')) {
$attrs = $request->post();
$attrs['user_id'] = Auth::user()->id;

$this->newsSvc->updateNews($attrs);
} elseif ($request->isMethod('delete')) {
$id = $request->input('news_id');
$this->newsSvc->deleteNews($id);
Expand Down
15 changes: 4 additions & 11 deletions app/Http/Controllers/Admin/ExpenseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use App\Repositories\AirlineRepository;
use App\Repositories\ExpenseRepository;
use App\Services\ExportService;
use App\Services\FinanceService;
use App\Services\ImportService;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
Expand All @@ -23,17 +24,11 @@ class ExpenseController extends Controller
{
use Importable;

/**
* expensesController constructor.
*
* @param AirlineRepository $airlineRepo
* @param ExpenseRepository $expenseRepo
* @param ImportService $importSvc
*/
public function __construct(
private readonly AirlineRepository $airlineRepo,
private readonly ExpenseRepository $expenseRepo,
private readonly ImportService $importSvc
private readonly ImportService $importSvc,
private readonly FinanceService $financeSvc,
) {
}

Expand Down Expand Up @@ -81,9 +76,7 @@ public function create(): View
*/
public function store(Request $request): RedirectResponse
{
$input = $request->all();
$input['ref_model'] = Expense::class;
$this->expenseRepo->create($input);
$this->financeSvc->addExpense($request->all(), null, null);

Flash::success('Expense saved successfully.');

Expand Down
27 changes: 9 additions & 18 deletions app/Http/Controllers/Admin/SubfleetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use App\Services\ExportService;
use App\Services\FareService;
use App\Services\FileService;
use App\Services\FinanceService;
use App\Services\FleetService;
use App\Services\ImportService;
use Illuminate\Http\RedirectResponse;
Expand All @@ -34,19 +35,6 @@ class SubfleetController extends Controller
{
use Importable;

/**
* SubfleetController constructor.
*
* @param AircraftRepository $aircraftRepo
* @param FareRepository $fareRepo
* @param FareService $fareSvc
* @param FileService $fileSvc
* @param FleetService $fleetSvc
* @param ImportService $importSvc
* @param RankRepository $rankRepo
* @param SubfleetRepository $subfleetRepo
* @param TypeRatingRepository $typeratingRepo
*/
public function __construct(
private readonly AircraftRepository $aircraftRepo,
private readonly FareRepository $fareRepo,
Expand All @@ -56,7 +44,8 @@ public function __construct(
private readonly ImportService $importSvc,
private readonly RankRepository $rankRepo,
private readonly SubfleetRepository $subfleetRepo,
private readonly TypeRatingRepository $typeratingRepo
private readonly TypeRatingRepository $typeratingRepo,
private readonly FinanceService $financeSvc,
) {
}

Expand Down Expand Up @@ -445,6 +434,7 @@ protected function return_typeratings_view(?Subfleet $subfleet): View
*/
public function expenses(int $id, Request $request): View
{
/** @var Subfleet $subfleet */
$subfleet = $this->subfleetRepo->findWithoutFail($id);
if (empty($subfleet)) {
return $this->return_expenses_view($subfleet);
Expand All @@ -458,10 +448,11 @@ public function expenses(int $id, Request $request): View
* update specific rank data
*/
if ($request->isMethod('post')) {
$expense = new Expense($request->post());
$expense->ref_model = Subfleet::class;
$expense->ref_model_id = $subfleet->id;
$expense->save();
$this->financeSvc->addExpense(
$request->post(),
$subfleet,
$subfleet->airline_id
);
} elseif ($request->isMethod('put')) {
$expense = Expense::findOrFail($request->input('expense_id'));
$expense->{$request->name} = $request->value;
Expand Down
10 changes: 10 additions & 0 deletions app/Http/Controllers/Api/MaintenanceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Http\Controllers\Api;

use App\Console\Cron;
use App\Console\Kernel;
use App\Contracts\Controller;
use App\Exceptions\CronInvalid;
use Illuminate\Http\JsonResponse;
Expand All @@ -25,6 +26,15 @@ public function cron(Request $request, string $id): JsonResponse
throw new CronInvalid();
}

// Create a console kernel instance
$consoleKernel = app()->make(Kernel::class);

// Run a null artisan thing just so Laravel internals can be setup properly
$status = $consoleKernel->handle(
new \Symfony\Component\Console\Input\ArgvInput(),
new \Symfony\Component\Console\Output\NullOutput()
);

$cron = app(Cron::class);
$run = $cron->run();

Expand Down
Loading

0 comments on commit c70740c

Please sign in to comment.