refactor(pirep): migrate Dashboard, Api/Pirep, Api/Acars controllers to Eloquent
This commit is contained in:
parent
e20844a999
commit
80be8da6c3
@ -14,8 +14,6 @@ use App\Http\Resources\Pirep as PirepResource;
|
||||
use App\Models\Acars;
|
||||
use App\Models\Enums\AcarsType;
|
||||
use App\Models\Pirep;
|
||||
use App\Repositories\AcarsRepository;
|
||||
use App\Repositories\PirepRepository;
|
||||
use App\Services\GeoService;
|
||||
use Carbon\Carbon;
|
||||
use DateTime;
|
||||
@ -31,9 +29,7 @@ class AcarsController extends Controller
|
||||
* AcarsController constructor.
|
||||
*/
|
||||
public function __construct(
|
||||
private readonly AcarsRepository $acarsRepo,
|
||||
private readonly GeoService $geoSvc,
|
||||
private readonly PirepRepository $pirepRepo
|
||||
private readonly GeoService $geoSvc
|
||||
) {}
|
||||
|
||||
/**
|
||||
@ -56,7 +52,7 @@ class AcarsController extends Controller
|
||||
*/
|
||||
public function live_flights()
|
||||
{
|
||||
$pireps = $this->acarsRepo->getPositions(setting('acars.live_time'))->filter(
|
||||
$pireps = Pirep::activeFlights(setting('acars.live_time'))->get()->filter(
|
||||
fn (Pirep $pirep) => $pirep->position !== null
|
||||
);
|
||||
|
||||
@ -68,7 +64,7 @@ class AcarsController extends Controller
|
||||
*/
|
||||
public function pireps_geojson(Request $request): JsonResponse
|
||||
{
|
||||
$pireps = $this->acarsRepo->getPositions(setting('acars.live_time'));
|
||||
$pireps = Pirep::activeFlights(setting('acars.live_time'))->get();
|
||||
$positions = $this->geoSvc->getFeatureForLiveFlights($pireps);
|
||||
|
||||
return response()->json([
|
||||
@ -98,7 +94,7 @@ class AcarsController extends Controller
|
||||
*/
|
||||
public function acars_get(string $id, Request $request): AcarsRouteResource
|
||||
{
|
||||
$pirep = $this->pirepRepo->find($id);
|
||||
$pirep = Pirep::find($id);
|
||||
if (empty($pirep)) {
|
||||
throw new PirepNotFound($id);
|
||||
}
|
||||
|
||||
@ -30,7 +30,6 @@ use App\Models\PirepFare;
|
||||
use App\Models\PirepFieldValue;
|
||||
use App\Models\User;
|
||||
use App\Repositories\JournalRepository;
|
||||
use App\Repositories\PirepRepository;
|
||||
use App\Services\Finance\PirepFinanceService;
|
||||
use App\Services\PirepService;
|
||||
use App\Services\UserService;
|
||||
@ -52,7 +51,6 @@ class PirepController extends Controller
|
||||
public function __construct(
|
||||
private readonly PirepFinanceService $financeSvc,
|
||||
private readonly JournalRepository $journalRepo,
|
||||
private readonly PirepRepository $pirepRepo,
|
||||
private readonly PirepService $pirepSvc,
|
||||
private readonly UserService $userSvc
|
||||
) {}
|
||||
@ -167,9 +165,7 @@ class PirepController extends Controller
|
||||
'user',
|
||||
];
|
||||
|
||||
$pirep = $this->pirepRepo
|
||||
->with($with)
|
||||
->find($id);
|
||||
$pirep = Pirep::with($with)->findOrFail($id);
|
||||
|
||||
return new PirepResource($pirep);
|
||||
}
|
||||
|
||||
@ -3,9 +3,8 @@
|
||||
namespace App\Http\Controllers\Frontend;
|
||||
|
||||
use App\Contracts\Controller;
|
||||
use App\Models\Pirep;
|
||||
use App\Models\User;
|
||||
use App\Repositories\PirepRepository;
|
||||
use Exception;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\View\View;
|
||||
|
||||
@ -14,19 +13,11 @@ use Illuminate\View\View;
|
||||
*/
|
||||
class DashboardController extends Controller
|
||||
{
|
||||
/**
|
||||
* DashboardController constructor.
|
||||
*/
|
||||
public function __construct(
|
||||
private readonly PirepRepository $pirepRepo
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Show the application dashboard.
|
||||
*/
|
||||
public function index(): View
|
||||
{
|
||||
$last_pirep = null;
|
||||
// Support retrieval of deleted relationships
|
||||
$with_pirep = [
|
||||
'aircraft' => function ($query) {
|
||||
@ -45,9 +36,9 @@ class DashboardController extends Controller
|
||||
$user = Auth::user();
|
||||
$user->loadMissing('journal');
|
||||
|
||||
try {
|
||||
$last_pirep = $this->pirepRepo->with($with_pirep)->find($user->last_pirep_id);
|
||||
} catch (Exception $e) {
|
||||
$last_pirep = null;
|
||||
if ($user->last_pirep_id) {
|
||||
$last_pirep = Pirep::with($with_pirep)->find($user->last_pirep_id);
|
||||
}
|
||||
|
||||
// Get the current airport for the weather
|
||||
|
||||
Loading…
Reference in New Issue
Block a user