Added Notifications
This commit is contained in:
@@ -22,10 +22,17 @@ class AchievementController extends Controller
|
||||
|
||||
$userAchievements = $user->achievements()
|
||||
->with('achievement')
|
||||
->select(['achievement_id', 'progress'])
|
||||
->orderBy('achievement_id')
|
||||
->get()
|
||||
->keyBy('achievement_id');
|
||||
|
||||
$unlockedByCategory = $achievements->map(fn($group) =>
|
||||
$group->filter(fn($a) => $userAchievements->get($a->id)?->unlocked)->count()
|
||||
);
|
||||
|
||||
$unlockedCount = $userAchievements->filter(fn($ua) => $ua->unlocked)->count();
|
||||
|
||||
return Inertia::render('UserAchievements', [
|
||||
'user' => $user,
|
||||
'canEdit' => auth()->id() === $user->id,
|
||||
@@ -33,6 +40,9 @@ class AchievementController extends Controller
|
||||
'achievements' => $achievements,
|
||||
'userAchievements' => $userAchievements,
|
||||
'loggedInUser' => auth()->user(),
|
||||
'unlockedCount' => $unlockedCount,
|
||||
'unlockedByCategory' => $unlockedByCategory,
|
||||
'totalAchievements' => $achievements->flatten()->count(),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -98,6 +108,7 @@ class AchievementController extends Controller
|
||||
'airlines' => $airlines,
|
||||
'continents' => $continents,
|
||||
'aircraft_families' => $aircraftFamilies,
|
||||
'achievementCount' => $user->unlockedAchievements()->count(),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -8,9 +8,11 @@ use App\Models\Airport;
|
||||
use App\Models\CrewType;
|
||||
use App\Models\FlightClass;
|
||||
use App\Models\FlightReason;
|
||||
use App\Models\IataEquipmentCode;
|
||||
use App\Models\SeatType;
|
||||
use App\Models\UserAction;
|
||||
use App\Models\UserFlight;
|
||||
use App\Services\FlightStatsService;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
@@ -24,7 +26,24 @@ class FlightController extends Controller
|
||||
return [
|
||||
'flight_number' => ['nullable', 'string', 'max:10'],
|
||||
'departure_date' => ['required', 'date'],
|
||||
'arrival_date' => ['required', 'date'],
|
||||
'arrival_date' => ['required', 'date', function ($attribute, $value, $fail) {
|
||||
$from = request()->input('from_id');
|
||||
$to = request()->input('to_id');
|
||||
|
||||
if (!$from || !$to) return;
|
||||
|
||||
$departureAirport = Airport::find($from);
|
||||
$arrivalAirport = Airport::find($to);
|
||||
|
||||
if (!$departureAirport || !$arrivalAirport) return;
|
||||
|
||||
$departureUtc = Carbon::createFromFormat('Y-m-d\TH:i', request()->input('departure_date'), $departureAirport->timezone)->utc();
|
||||
$arrivalUtc = Carbon::createFromFormat('Y-m-d\TH:i', $value, $arrivalAirport->timezone)->utc();
|
||||
|
||||
if ($arrivalUtc->lessThanOrEqualTo($departureUtc)) {
|
||||
$fail('The arrival time must be after the departure time, accounting for time zones.');
|
||||
}
|
||||
}],
|
||||
'from_id' => ['required', 'integer', 'exists:airports,id'],
|
||||
'to_id' => ['required', 'integer', 'exists:airports,id'],
|
||||
'airline_id' => ['nullable', 'integer', 'exists:airlines,id'],
|
||||
@@ -44,24 +63,74 @@ class FlightController extends Controller
|
||||
{
|
||||
$number = strtoupper(trim($request->query('number', '')));
|
||||
|
||||
// Extract the airline code prefix — letters at the start e.g. "QF" from "QF1"
|
||||
preg_match('/^([A-Z]{2,3})/', $number, $matches);
|
||||
$code = $matches[1] ?? null;
|
||||
$isIata = strlen($code) === 2;
|
||||
$codeColumn = $isIata ? 'IATA_code' : 'ICAO_code';
|
||||
preg_match('/^([A-Z]{2,3})(\d+)/', $number, $matches);
|
||||
$code = $matches[1] ?? null;
|
||||
$flightNumber = $matches[2] ?? null;
|
||||
$isIata = strlen($code) === 2;
|
||||
$codeColumn = $isIata ? 'IATA_code' : 'ICAO_code';
|
||||
|
||||
$apiAirlineCodes = [];
|
||||
$fromOptions = [];
|
||||
$toOptions = [];
|
||||
$aircraftOptions = [];
|
||||
|
||||
if (strlen($number) >= 3 && $isIata) {
|
||||
$flightStatsApi = new FlightStatsService();
|
||||
$flightData = $flightStatsApi->fetchFlightData($code, $flightNumber);
|
||||
|
||||
if ($flightData) {
|
||||
$apiAirlineCodes = $flightData->airline_fs_codes;
|
||||
|
||||
$fromOptions = Airport::where('iata_code', $flightData->departure_iata)
|
||||
->get()
|
||||
->map(fn($a) => ['value' => $a->id, 'title' => $a->display_name, 'country_code' => strtolower($a->region->country->code)])
|
||||
->values()
|
||||
->toArray();
|
||||
|
||||
$toOptions = Airport::where('iata_code', $flightData->arrival_iata)
|
||||
->get()
|
||||
->map(fn($a) => ['value' => $a->id, 'title' => $a->display_name, 'country_code' => strtolower($a->region->country->code)])
|
||||
->values()
|
||||
->toArray();
|
||||
|
||||
if($flightData->equipment_iata){
|
||||
$equipment = IataEquipmentCode::where('iata_code', $flightData->equipment_iata)->first();
|
||||
if ($equipment) {
|
||||
$bestGuess = $flightStatsApi->guessAircraftFromIata($flightData->equipment_iata);
|
||||
|
||||
$aircraftOptions = Aircraft::where('designator', $equipment->icao_code)
|
||||
->get()
|
||||
->sortBy(fn($a) => $a->id === $bestGuess?->id ? 0 : 1)
|
||||
->map(fn($a) => ['value' => $a->id, 'title' => $a->display_name])
|
||||
->values()
|
||||
->toArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Airlines from the typed code + any additional codes from the API, merged and deduped by id
|
||||
$allCodes = array_unique(array_filter([$code, ...$apiAirlineCodes]));
|
||||
|
||||
$airlines = Airline::where(function ($q) use ($codeColumn, $code, $allCodes) {
|
||||
$q->whereIn($codeColumn, $allCodes);
|
||||
})
|
||||
->get()
|
||||
->unique('id')
|
||||
->sortBy(function ($a) use ($code, $flightData) {
|
||||
if ($a->IATA_code === $flightData?->operating_fs) return 0;
|
||||
if ($a->IATA_code === $code) return 1;
|
||||
return 2;
|
||||
})
|
||||
->map(fn($a) => ['value' => $a->id, 'title' => $a->display_name, 'logo_url' => $a->logo_url])
|
||||
->values()
|
||||
->toArray();
|
||||
|
||||
$airlines = $code
|
||||
? Airline::where($codeColumn, $code)
|
||||
->get()
|
||||
->map(fn ($airline) => ['value' => $airline->id, 'title' => $airline->display_name, 'logo_url' => $airline->logo_url])
|
||||
->values()
|
||||
->toArray()
|
||||
: collect()->toArray();
|
||||
return response()->json([
|
||||
'airline_options' => $airlines,
|
||||
'from_options' => [],
|
||||
'to_options' => [],
|
||||
'aircraft_options' => [],
|
||||
'from_options' => $fromOptions,
|
||||
'to_options' => $toOptions,
|
||||
'aircraft_options' => $aircraftOptions,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -35,37 +35,21 @@ class FlightImportController extends Controller
|
||||
->toArray();
|
||||
}
|
||||
|
||||
public function getPossibleAircraft(string $aircraftQuery) {
|
||||
public function getPossibleAircraft(string $aircraftQuery): array
|
||||
{
|
||||
preg_match('/\((\w+)\)/', $aircraftQuery, $matches);
|
||||
$designator = $matches[1] ?? null;
|
||||
|
||||
$sortOverrides = [
|
||||
'B788' => "CASE WHEN model_full_name ILIKE '%BBJ%' THEN 1 ELSE 0 END",
|
||||
'B789' => "CASE WHEN model_full_name ILIKE '%BBJ%' THEN 1 ELSE 0 END",
|
||||
];
|
||||
if (!$designator) return [];
|
||||
|
||||
if(!$designator){
|
||||
$aircraft = [];
|
||||
} else {
|
||||
|
||||
$aircraft = Aircraft::when($designator, fn($query) => $query->where('designator', 'ilike', $designator))
|
||||
->when(
|
||||
isset($sortOverrides[$designator]),
|
||||
fn($q) => $q->orderByRaw($sortOverrides[$designator])
|
||||
)
|
||||
->orderBy('model_full_name')
|
||||
->limit(10)
|
||||
->get(['id', 'manufacturer_code', 'model_full_name', 'designator'])
|
||||
->map(fn($aircraft) => [
|
||||
'value' => $aircraft->id,
|
||||
'title' => $aircraft->display_name,
|
||||
])
|
||||
->values()
|
||||
->toArray();
|
||||
|
||||
}
|
||||
|
||||
return $aircraft;
|
||||
return Aircraft::where('designator', 'ilike', $designator)
|
||||
->orderByDesc('preferred')
|
||||
->orderBy('model_full_name')
|
||||
->limit(10)
|
||||
->get(['id', 'manufacturer_code', 'model_full_name', 'designator', 'preferred'])
|
||||
->map(fn($a) => ['value' => $a->id, 'title' => $a->display_name])
|
||||
->values()
|
||||
->toArray();
|
||||
}
|
||||
|
||||
public function getPossibleAirports(string $airportQuery) {
|
||||
|
||||
Reference in New Issue
Block a user