Skip to content

Commit 360fbb7

Browse files
authored
🚑 Hotfix: ManualTrip & GeoService (#3277)
1 parent 5c88d59 commit 360fbb7

File tree

4 files changed

+47
-2
lines changed

4 files changed

+47
-2
lines changed

app/Http/Controllers/Backend/Support/LocationController.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ public function calculateLivePosition(): ?LivePointDto {
114114
$point ?? $recentPoint,
115115
$distance < 1 ? 0 : $meters / $distance
116116
);
117+
if ($currentPosition === null) {
118+
return null;
119+
}
117120

118121
$polyline->features = array_slice($polyline->features, $key);
119122
array_unshift($polyline->features, Feature::fromCoordinate($currentPosition));
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace App\Http\Requests;
4+
5+
use Illuminate\Foundation\Http\FormRequest;
6+
7+
class ManualTripCreationRequest extends FormRequest
8+
{
9+
public function authorize(): bool
10+
{
11+
if (auth()->user()?->can('disallow-manual-trips')) {
12+
return false;
13+
}
14+
15+
return true;
16+
}
17+
18+
public function rules(): array
19+
{
20+
return [
21+
'category' => ['required', new Enum(HafasTravelType::class)],
22+
'lineName' => ['required'],
23+
'journeyNumber' => ['nullable', 'numeric', 'min:1'],
24+
'operatorId' => ['nullable', 'numeric', 'exists:hafas_operators,id'],
25+
'originId' => ['required', 'exists:train_stations,id'],
26+
'originDeparturePlanned' => ['required', 'date'],
27+
'originDepartureReal' => ['nullable', 'date'],
28+
'destinationId' => ['required', 'exists:train_stations,id'],
29+
'destinationArrivalPlanned' => ['required', 'date'],
30+
'destinationArrivalReal' => ['nullable', 'date'],
31+
'stopovers.*.stationId' => ['required', 'exists:train_stations,id'],
32+
'stopovers.*.arrival' => ['required_without:stopovers.*.departure', 'required_with:stopovers.*.arrivalReal', 'date'],
33+
'stopovers.*.arrivalReal' => ['nullable', 'date'],
34+
'stopovers.*.departure' => ['required_without:stopovers.*.arrival,null', 'required_with:stopovers.*.departureReal', 'date'],
35+
'stopovers.*.departureReal' => ['nullable', 'date'],
36+
];
37+
}
38+
}

app/Objects/LineSegment.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function calculateDistance(): int {
2525
/**
2626
* @deprecated Use GeoService::interpolatePoint instead
2727
*/
28-
public function interpolatePoint(float $percent): Coordinate {
28+
public function interpolatePoint(float $percent): ?Coordinate {
2929
return (new GeoService())->interpolatePoint($this->start, $this->finish, $percent);
3030
}
3131
}

app/Services/GeoService.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ public function getBoundingBox(Coordinate $center, int $radius, int $precision =
4141
}
4242

4343

44-
public function interpolatePoint(Coordinate $start, Coordinate $end, float $percent): Coordinate {
44+
public function interpolatePoint(?Coordinate $start, ?Coordinate $end, float $percent): ?Coordinate {
45+
if ($start === null || $end === null) {
46+
return $start ?? $end ?? null;
47+
}
48+
4549
return new Coordinate(
4650
round($start->latitude + $percent * ($end->latitude - $start->latitude), 6),
4751
round($start->longitude + $percent * ($end->longitude - $start->longitude), 6)

0 commit comments

Comments
 (0)