Updated logo API

This commit is contained in:
2026-04-25 22:57:18 +10:00
parent 678096b463
commit de183995b6
26 changed files with 1088 additions and 64 deletions
+31
View File
@@ -0,0 +1,31 @@
<?php
namespace App\Http\Controllers;
use App\Models\UserAction;
use Illuminate\Http\Request;
use Inertia\Inertia;
class FeedController extends Controller
{
public function view()
{
$user = auth()->user();
$followeeIds = $user->following()->pluck('followee_id');
$feed = UserAction::whereIn('user_id', $followeeIds)
->whereNotIn('type', ['flight_deleted'])
->with([
'user',
])
->latest()
->limit(50)
->get();
return Inertia::render('Feed', [
'user' => $user,
'feed' => $feed,
]);
}
}
+83 -21
View File
@@ -53,7 +53,9 @@ class FlightController extends Controller
$airlines = $code
? Airline::where($codeColumn, $code)
->get()
->map(fn ($airline) => ['value' => $airline->id, 'title' => $airline->display_name])
->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,
@@ -74,27 +76,23 @@ class FlightController extends Controller
];
}
private function recordChanges(UserFlight $flight): void
private function recordChanges(UserFlight $flight, array $dirty, array $original, array $updated): void
{
$dirty = $flight->getDirty();
if (empty($dirty)) {
return;
}
$actions = [];
$changes = [];
foreach ($dirty as $field => $newValue) {
$original = $flight->getOriginal($field);
$actions[] = [
'user_id' => $flight->user_id,
'user_flight_id' => $flight->id,
'message' => $this->formatChange($field, $original, $newValue),
'created_at' => now(),
'updated_at' => now(),
];
$changes[] = $this->formatChange($field, $flight->getOriginal($field), $newValue);
}
UserAction::insert($actions);
UserAction::create([
'user_id' => $flight->user_id,
'user_flight_id' => $flight->id,
'data' => [
'changes' => $changes,
'original' => $original,
'updated' => $updated,
],
'type' => 'flight_updated',
]);
}
private array $labelCache = [];
@@ -129,13 +127,17 @@ class FlightController extends Controller
return $this->labelCache[$cacheKey] = $label;
}
private function formatChange(string $field, mixed $from, mixed $to): string
private function formatChange(string $field, mixed $from, mixed $to): array
{
$label = str($field)->replace('_id', '')->replace('_', ' ')->title();
$fromLabel = $this->resolveLabel($field, $from);
$toLabel = $this->resolveLabel($field, $to);
return "{$label} changed from {$fromLabel} to {$toLabel}";
return [
'field' => $field,
'from' => $fromLabel,
'to' => $toLabel,
];
}
private function flightPayload(array $validated): array
@@ -168,9 +170,35 @@ class FlightController extends Controller
$newFlight = auth()->user()->flights()->create($this->flightPayload($validated));
UserAction::create([
'user_id' => $newFlight->user_id,
'type' => $newFlight->departure_date->isFuture() ? 'flight_booked' : 'flight_logged',
'data' => [
'flight' => $this->flightSnapshot($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)
{
$this->authorize('update', $flight);
@@ -178,12 +206,46 @@ class FlightController extends Controller
$validated = $request->validate($this->rules());
$flight->fill($this->flightPayload($validated));
$this->recordChanges($flight);
if (!$flight->isDirty()) {
return redirect()->route('profile.departure-board', [Auth::user()->name, $flight->id]);
}
$dirty = $flight->getDirty();
$original = $this->flightSnapshot($flight->id);
$flight->save();
$updated = $this->flightSnapshot($flight->id);
$this->recordChanges($flight, $dirty, $original, $updated);
return redirect()->route('profile.departure-board', [Auth::user()->name, $flight->id]);
}
public function delete(UserFlight $flight)
{
$this->authorize('delete', $flight);
$snapshot = $this->flightSnapshot($flight->id);
if(now()->utc()->isBefore($flight->departure_date)){
$action = 'flight_deleted';
} else {
$action = 'flight_cancelled';
}
UserAction::create([
'user_id' => $flight->user_id,
'type' => $action,
'data' => [
'flight' => $snapshot,
]
]);
$flight->delete();
return redirect()->route('profile.departure-board', [Auth::user()->name]);
}
public function staticData() : array {
return [
'seat_types' => SeatType::orderBy('id')->get()->toArray(),