Updated scheduled tasks
This commit is contained in:
@@ -78,6 +78,28 @@ class GetAircraftInfoForArrivedFlights extends Command
|
|||||||
$this->applyAndNotify($flight, $data, $airlineCode, $flightNumber);
|
$this->applyAndNotify($flight, $data, $airlineCode, $flightNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function splitFlightNumber(UserFlight $flight): array
|
||||||
|
{
|
||||||
|
$raw = strtoupper($flight->flight_number);
|
||||||
|
$airline = $flight->airline;
|
||||||
|
|
||||||
|
// Preferred: anchor on the airline's known codes rather than guessing.
|
||||||
|
foreach (array_filter([$airline?->iata_code, $airline?->icao_code]) as $code) {
|
||||||
|
$code = strtoupper($code);
|
||||||
|
if (str_starts_with($raw, $code) && preg_match('/^\d+$/', substr($raw, strlen($code)))) {
|
||||||
|
return [$code, substr($raw, strlen($code))];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fallback: regex guess.
|
||||||
|
// Covers: letter+digit (J2), digit+letter (9K, 4U), and 2-3 letter codes (AA, DAL).
|
||||||
|
if (preg_match('/^([A-Z]\d|\d[A-Z]|[A-Z]{2,3})(\d+)$/', $raw, $matches)) {
|
||||||
|
return [$matches[1], $matches[2]];
|
||||||
|
}
|
||||||
|
|
||||||
|
return [null, null];
|
||||||
|
}
|
||||||
|
|
||||||
protected function notifyLookupFailed(UserFlight $flight, string $airlineCode, string $flightNumber): void
|
protected function notifyLookupFailed(UserFlight $flight, string $airlineCode, string $flightNumber): void
|
||||||
{
|
{
|
||||||
Notification::create([
|
Notification::create([
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ class UserApiController extends ApiController
|
|||||||
{
|
{
|
||||||
public function nextFlight(?User $user): JsonResponse
|
public function nextFlight(?User $user): JsonResponse
|
||||||
{
|
{
|
||||||
$user = $user ?? auth()->user();
|
$user = $user?->exists ? $user : auth()->user();
|
||||||
|
|
||||||
if (!$user->id) {
|
if (!$user->id) {
|
||||||
return response()->json(['message' => 'User not found'], 404);
|
return response()->json(['message' => 'User not found'], 404);
|
||||||
@@ -48,8 +48,8 @@ class UserApiController extends ApiController
|
|||||||
'arrivalTime' => $arrival->format('H:i'),
|
'arrivalTime' => $arrival->format('H:i'),
|
||||||
'arrivalDateUtc' => $flight->arrival_date,
|
'arrivalDateUtc' => $flight->arrival_date,
|
||||||
'flightNumber' => $flight->flight_number,
|
'flightNumber' => $flight->flight_number,
|
||||||
'airlineName' => $flight->airline->name,
|
'airlineName' => $flight->airline?->name,
|
||||||
'aircraftType' => $flight->aircraft->manufacturer_code . ' ' . $flight->aircraft->model_full_name,
|
'aircraftType' => $flight->aircraft?->manufacturer_code . ' ' . $flight->aircraft?->model_full_name,
|
||||||
'logoUrl' => $flight->airline?->logo_url ?? '',
|
'logoUrl' => $flight->airline?->logo_url ?? '',
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,11 +64,14 @@ class FlightController extends Controller
|
|||||||
public function lookup(Request $request)
|
public function lookup(Request $request)
|
||||||
{
|
{
|
||||||
$number = strtoupper(trim($request->query('number', '')));
|
$number = strtoupper(trim($request->query('number', '')));
|
||||||
|
preg_match(
|
||||||
preg_match('/^([A-Z]{2,3})(\d+)/', $number, $matches);
|
'/^([A-Z]{3}|[A-Z]{2}|[A-Z]\d|\d[A-Z])(\d+)$/',
|
||||||
|
$number,
|
||||||
|
$matches
|
||||||
|
);
|
||||||
$code = $matches[1] ?? null;
|
$code = $matches[1] ?? null;
|
||||||
$flightNumber = $matches[2] ?? null;
|
$flightNumber = $matches[2] ?? null;
|
||||||
$isIata = strlen($code) === 2;
|
$isIata = $code !== null && strlen($code) === 2;
|
||||||
$codeColumn = $isIata ? 'iata_code' : 'icao_code';
|
$codeColumn = $isIata ? 'iata_code' : 'icao_code';
|
||||||
|
|
||||||
$apiAirlineCodes = [];
|
$apiAirlineCodes = [];
|
||||||
|
|||||||
@@ -20,8 +20,6 @@ Route::domain(config('app.api_domain'))->group(function () {
|
|||||||
Route::get('/flights/most-recent', [HomePageController::class ,'mostRecentFlights'])->name('home-page.most-recent-flights');
|
Route::get('/flights/most-recent', [HomePageController::class ,'mostRecentFlights'])->name('home-page.most-recent-flights');
|
||||||
Route::get('/feed/following', [FeedController::class ,'following'])->name('feed.following');
|
Route::get('/feed/following', [FeedController::class ,'following'])->name('feed.following');
|
||||||
Route::get('/feed/following-flights', [FeedController::class ,'followingFlights'])->name('feed.following-flights');
|
Route::get('/feed/following-flights', [FeedController::class ,'followingFlights'])->name('feed.following-flights');
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user