Updated scheduled tasks

This commit is contained in:
2026-07-02 23:11:46 +10:00
parent 4c98b33fb4
commit 00bd30fc5e
17 changed files with 397 additions and 667 deletions
-59
View File
@@ -232,8 +232,6 @@ class FlightController extends Controller
];
}
public function store(Request $request)
{
$validated = $request->validate($this->rules());
@@ -248,42 +246,10 @@ class FlightController extends Controller
],
]);
$this->notifyFollowersOnCreation($newFlight);
return redirect()->route('profile.departure-board', [Auth::user()->name, $newFlight->id]);
}
protected function notifyFollowersOnCreation(UserFlight $flight): void
{
$user = $flight->user;
$isFuture = $flight->departure_date->isFuture();
$title = $isFuture
? "{$user->name} booked a new flight"
: "{$user->name} logged a new flight";
$flightNumber = $flight->flight_number ? "{$flight->flight_number} from" : 'From';
$body = "{$flightNumber} {$flight->departureAirport->municipality} ({$flight->departureAirport->display_code}) → {$flight->arrivalAirport->municipality} ({$flight->arrivalAirport->display_code}) on {$flight->departure_date_display}";
$url = route('profile.departure-board', [$user->name, $flight->id]);
$user->followers()->get()->each(function (User $follower) use ($title, $body, $url, $isFuture) {
$notifyForFuture = $follower->getSetting('notify_on_upcoming_flight_added');
$notifyForHistoric = $follower->getSetting('notify_on_historic_flight_added');
if (($isFuture && $notifyForFuture) || (!$isFuture && $notifyForHistoric)) {
Notification::create([
'user_id' => $follower->id,
'title' => $title,
'body' => $body,
'url' => $url,
]);
}
}
);
}
public function update(Request $request, UserFlight $flight)
{
@@ -323,36 +289,11 @@ class FlightController extends Controller
],
]);
if ($isFuture) {
$this->notifyFollowersOnCancellation($flight);
}
$flight->delete();
return redirect()->route('profile.'.$referrer, [Auth::user()->name]);
}
protected function notifyFollowersOnCancellation(UserFlight $flight): void
{
$user = $flight->user;
$title = "{$user->name} cancelled a flight";
$flightNumber = $flight->flight_number ? "{$flight->flight_number} from" : 'From';
$body = "{$flightNumber} {$flight->departureAirport->municipality} ({$flight->departureAirport->display_code}) → {$flight->arrivalAirport->municipality} ({$flight->arrivalAirport->display_code}) on {$flight->departure_date_display}";
$url = route('profile.view', [$user->name]);
$user->followers()->get()->each(function (User $follower) use ($title, $body, $url) {
if ($follower->getSetting('notify_on_flight_cancellation')) {
Notification::create([
'user_id' => $follower->id,
'title' => $title,
'body' => $body,
'url' => $url,
]);
}
});
}
public function staticData() : array {
return [
'seat_types' => SeatType::orderBy('id')->get()->toArray(),