Added achievement data

This commit is contained in:
2026-04-28 22:16:21 +10:00
parent 14aed7bf6e
commit b94b1d8ec2
43 changed files with 1559 additions and 130 deletions
@@ -0,0 +1,33 @@
<?php
namespace App\Http\Controllers;
use App\Models\Achievement;
use App\Models\User;
use Illuminate\Http\Request;
use Inertia\Inertia;
class AchievementController extends Controller
{
public function index(User $user)
{
$achievements = Achievement::with(['category', 'difficulty'])
->get()
->groupBy(fn(Achievement $a) => $a->category->name)
->map(fn($group) => $group->sortBy('id')->values());
$userAchievements = $user->achievements()
->with('achievement')
->orderBy('achievement_id')
->get()
->keyBy('achievement_id');
return Inertia::render('UserAchievements', [
'user' => $user,
'canEdit' => auth()->id() === $user->id,
'isFollowing' => auth()->check() && auth()->user()->isFollowing($user),
'achievements' => $achievements,
'userAchievements' => $userAchievements,
]);
}
}
+4 -20
View File
@@ -85,7 +85,6 @@ class FlightController extends Controller
UserAction::create([
'user_id' => $flight->user_id,
'user_flight_id' => $flight->id,
'data' => [
'changes' => $changes,
'original' => $original,
@@ -174,29 +173,14 @@ class FlightController extends Controller
'user_id' => $newFlight->user_id,
'type' => $newFlight->departure_date->isFuture() ? 'flight_booked' : 'flight_logged',
'data' => [
'flight' => $this->flightSnapshot($newFlight->id),
'flight' => $newFlight->snapshot($newFlight->id),
],
]);
return redirect()->route('profile.departure-board', [Auth::user()->name, $newFlight->id]);
}
private function flightSnapshot(int $id): array
{
return UserFlight::with([
'departureAirport',
'departureAirport.region.country',
'arrivalAirport',
'arrivalAirport.region.country',
'aircraft',
'airline',
'airline.country',
'flightClass',
'seatType',
'flightReason',
'crewType',
])->find($id)->toArray();
}
public function update(Request $request, UserFlight $flight)
@@ -212,11 +196,11 @@ class FlightController extends Controller
}
$dirty = $flight->getDirty();
$original = $this->flightSnapshot($flight->id);
$original = $flight->snapshot($flight->id);
$flight->save();
$updated = $this->flightSnapshot($flight->id);
$updated = $flight->snapshot($flight->id);
$this->recordChanges($flight, $dirty, $original, $updated);
return redirect()->route('profile.departure-board', [Auth::user()->name, $flight->id]);
@@ -9,6 +9,7 @@ use App\Models\FlightClass;
use App\Models\FlightReason;
use App\Models\ImportedFlight;
use App\Models\SeatType;
use App\Models\UserAction;
use App\Models\UserFlight;
use Carbon\Carbon;
use Illuminate\Http\Request;
@@ -128,10 +129,11 @@ class FlightImportController extends Controller
})
->orderByDesc('active')
->limit(10)
->get(['id', 'name', 'IATA_code', 'ICAO_code'])
->get(['id', 'name', 'IATA_code', 'ICAO_code', 'internal_name'])
->map(fn($airline) => [
'value' => $airline->id,
'title' => $airline->display_name,
'logo_url' => $airline->logo_url,
])
->values()
->toArray();
@@ -243,7 +245,7 @@ class FlightImportController extends Controller
$arrival = $durationArrival;
}
UserFlight::create([
$newFlight = UserFlight::create([
'user_id' => $user->id,
'departure_date' => $departure,
'arrival_date' => $arrival,
@@ -260,6 +262,14 @@ class FlightImportController extends Controller
'note' => $validated['note'] ?? null,
]);
UserAction::create([
'user_id' => $newFlight->user_id,
'type' => $newFlight->departure_date->isFuture() ? 'flight_booked' : 'flight_imported',
'data' => [
'flight' => $newFlight->snapshot($newFlight->id),
],
]);
ImportedFlight::destroy($validated['imported_flight_id']);
return to_route('reconcile');
}
@@ -11,13 +11,12 @@ use Inertia\Inertia;
class FlightProfileController extends Controller
{
public function profileData(User $user, string $view, ?int $selectedFlightId = null) : array {
$flights = $user->FlightController()->flights();
return [
'user' => $user,
'canEdit' => auth()->check() && auth()->id() === $user->id,
'flights' => UserFlightResource::collection($flights)->resolve(),
'initialView' => $view,
'selectedFlightId' => $selectedFlightId,
'flight_api_url' => '/data/user/'.$user->name.'/flights',
'isFollowing' => auth()->check() && auth()->user()->isFollowing($user),
];
}
@@ -0,0 +1,17 @@
<?php
namespace App\Http\Controllers;
use App\Models\Notification;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Http\Request;
class NotificationController extends Controller
{
use AuthorizesRequests;
public function markRead(Request $request, Notification $notification)
{
$this->authorize('update', $notification);
$notification->markAsRead();
}
}
@@ -23,6 +23,7 @@ class UserFlightController extends Controller
'arrivalAirport.region.country',
'arrivalAirport.region.continent',
'airline.country',
'airline.alliance',
'aircraft',
'seatType',
'flightReason',
@@ -34,8 +34,16 @@ class HandleInertiaRequests extends Middleware
'logo_api_url' => config('app.logo_api_url'),
'auth' => [
'user' => $request->user(),
'isLoggedIn' => $request->user() !== null,
],
'achievement_notifications' => fn() => $request->user()
? $request->user()
->notifications()
->with('achievement')
->where('is_achievement', true)
->whereNull('read_at')
->latest()
->get()
: [],
];
}
}