64 lines
2.1 KiB
PHP
64 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\User;
|
|
use App\Models\UserFlight;
|
|
use App\Http\Resources\UserFlightResource;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Inertia\Inertia;
|
|
|
|
class FlightProfileController extends Controller
|
|
{
|
|
public static function getUserFlightApiURL(User $user){
|
|
return '/data/user/'.$user->name.'/flights';
|
|
}
|
|
|
|
public function profileData(User $user, string $view, ?int $selectedFlightId = null) : array {
|
|
return [
|
|
'user' => $user,
|
|
'canEdit' => (auth()->check() && auth()->id() === $user->id) || auth()->user()->hasRole('admin'),
|
|
'initialView' => $view,
|
|
'selectedFlightId' => $selectedFlightId,
|
|
'flight_api_url' => self::getUserFlightApiURL($user),
|
|
'isFollowing' => auth()->check() && auth()->user()->isFollowing($user),
|
|
'flightCount' => $user->departedFlights()->count(),
|
|
];
|
|
}
|
|
|
|
public function departureBoard(User $user, ?UserFlight $flight = null){
|
|
$profileData = $this->profileData($user, 'board', $flight?->id);
|
|
return Inertia::render('UserProfile', $profileData);
|
|
}
|
|
|
|
public function map(User $user){
|
|
$profileData = $this->profileData($user, 'map');
|
|
return Inertia::render('UserProfile', $profileData);
|
|
}
|
|
|
|
public function boardingPasses(User $user){
|
|
$profileData = $this->profileData($user, 'passes');
|
|
return Inertia::render('UserProfile', $profileData);
|
|
}
|
|
|
|
public function view(User $user)
|
|
{
|
|
return $this->departureBoard($user);
|
|
}
|
|
|
|
public function flight(User $user, UserFlight $userFlight)
|
|
{
|
|
if($userFlight->user_id !== $user->id){
|
|
abort(404);
|
|
}
|
|
|
|
return Inertia::render('UserFlight', [
|
|
'flightCount' => $user->departedFlights()->count(),
|
|
'flight' => $userFlight->snapshot($userFlight->id),
|
|
'canEdit' => auth()->check() && auth()->id() === $user->id,
|
|
'user' => $user,
|
|
'isFollowing' => auth()->check() && auth()->user()->isFollowing($user),
|
|
]);
|
|
}
|
|
}
|