Added Notifications

This commit is contained in:
2026-05-16 23:48:18 +10:00
parent 69d72e0912
commit 1d5b9f340f
61 changed files with 4204 additions and 182 deletions
+59 -10
View File
@@ -3,6 +3,9 @@
namespace App\Http\Controllers;
use App\Models\Achievement;
use App\Models\Aircraft;
use App\Models\Alliance;
use App\Models\Continent;
use App\Models\Country;
use App\Models\User;
use Illuminate\Http\Request;
@@ -15,7 +18,7 @@ class AchievementController extends Controller
$achievements = Achievement::with(['category', 'difficulty'])
->get()
->groupBy(fn(Achievement $a) => $a->category->name)
->map(fn($group) => $group->sortBy('id')->values());
->map(fn($group) => $group->sortBy('sort_order')->values());
$userAchievements = $user->achievements()
->with('achievement')
@@ -29,26 +32,72 @@ class AchievementController extends Controller
'isFollowing' => auth()->check() && auth()->user()->isFollowing($user),
'achievements' => $achievements,
'userAchievements' => $userAchievements,
'loggedInUser' => auth()->user(),
]);
}
function getRegionsByCountryCode(string $countryCode)
{
return Country::whereCode($countryCode)
->first()
->regions()
->orderBy('name')
->get()
->toArray();
}
public function specific(User $user, Achievement $achievement)
{
$regions = match($achievement->internal_name){
'fun_challenges.australian_states' => Country::where('code', 'AU')->first()->regions->toArray(),
'fun_challenges.chinese_provinces' => Country::where('code', 'CN')->first()->regions->toArray(),
'fun_challenges.canadian_provinces' => Country::where('code', 'CA')->first()->regions->toArray(),
'fun_challenges.us_states' => Country::where('code', 'US')->first()->regions->toArray(),
'fun_challenges.australian_states' => $this->getRegionsByCountryCode('AU'),
'fun_challenges.chinese_provinces' => $this->getRegionsByCountryCode('CN'),
'fun_challenges.canadian_provinces' => $this->getRegionsByCountryCode('CA'),
'fun_challenges.brazilian_states' => $this->getRegionsByCountryCode('BR'),
'fun_challenges.us_states' => $this->getRegionsByCountryCode('US'),
default => [],
};
$allianceInternalName = match($achievement->internal_name){
'airlines_alliances.all_star_alliance' => 'star_alliance',
'airlines_alliances.all_oneworld' => 'oneworld',
'airlines_alliances.all_skyteam' => 'skyteam',
'airlines_alliances.all_vanilla_alliance' => 'vanilla_alliance',
default => null,
};
$continents = match($achievement->internal_name){
'countries_continents.all_continent_pairs_one_way', 'countries_continents.all_continent_pairs_both_ways' => Continent::all()->toArray(),
default => [],
};
$alliance = null;
$airlines = [];
if ($allianceInternalName) {
$alliance = Alliance::where('internal_name', $allianceInternalName)
->with('airlines')
->firstOrFail();
$airlines = $alliance->airlines()->with('country')->orderBy('name')->get();
}
$aircraftFamilies = match($achievement->internal_name){
'aircraft.all_boeing_7x7' => Aircraft::BOEING_FAMILIES,
'aircraft.all_airbus_a3xx' => Aircraft::AIRBUS_FAMILIES,
default => [],
};
return Inertia::render('Profile/UserAchievement', [
'user' => $user,
'achievement' => $achievement,
'user' => $user,
'achievement' => $achievement,
'loggedInUser' => auth()->user(),
'userAchievement' => $user->achievements()->where('achievement_id', $achievement->id)->first(),
'isFollowing' => auth()->check() && auth()->user()->isFollowing($user),
'flight_api_url' => FlightProfileController::getUserFlightApiURL($user),
'regions' => $regions,
'isFollowing' => auth()->check() && auth()->user()->isFollowing($user),
'flight_api_url' => FlightProfileController::getUserFlightApiURL($user),
'regions' => $regions,
'alliance' => $alliance,
'airlines' => $airlines,
'continents' => $continents,
'aircraft_families' => $aircraftFamilies,
]);
}
@@ -7,6 +7,7 @@ use App\Models\User;
use App\Models\UserFlight;
use Carbon\Carbon;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class UserApiController extends ApiController
{
@@ -47,7 +48,7 @@ class UserApiController extends ApiController
]);
}
public function flights(string $username): JsonResponse
public function flights(string $username, Request $request): JsonResponse
{
$user = User::where('name', 'ilike', $username)->first();
@@ -55,6 +56,6 @@ class UserApiController extends ApiController
return response()->json(['message' => 'User not found'], 404);
}
return response()->json($user->FlightController()->flights());
return response()->json($user->FlightController()->flights($request));
}
}
@@ -22,6 +22,7 @@ class FlightProfileController extends Controller
'selectedFlightId' => $selectedFlightId,
'flight_api_url' => self::getUserFlightApiURL($user),
'isFollowing' => auth()->check() && auth()->user()->isFollowing($user),
'flightCount' => $user->departedFlights()->count(),
];
}
@@ -15,7 +15,8 @@ class UserFlightController extends Controller
$this->user = $user;
}
public function flights(){
public function flights(?Request $request = null)
{
return UserFlight::where('user_id', $this->user->id)
->with([
'departureAirport.region.country',
@@ -30,6 +31,7 @@ class UserFlightController extends Controller
'flightClass',
'crewType'
])
->when($request?->boolean('departed_only'), fn($q) => $q->where('departure_date', '<=', now('UTC')))
->orderBy('departure_date', 'desc')
->get();
}