-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🚸 Change trip destination after checkin (#1103)
fixes #427
- Loading branch information
1 parent
f22e2ae
commit a690025
Showing
17 changed files
with
205 additions
and
79 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
app/Http/Controllers/Frontend/Transport/StatusController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Frontend\Transport; | ||
|
||
use App\Enum\Business; | ||
use App\Enum\PointReason; | ||
use App\Enum\StatusVisibility; | ||
use App\Exceptions\PermissionException; | ||
use App\Http\Controllers\Backend\Transport\TrainCheckinController; | ||
use App\Http\Controllers\Controller; | ||
use App\Models\Status; | ||
use App\Models\TrainStopover; | ||
use Illuminate\Database\Eloquent\ModelNotFoundException; | ||
use Illuminate\Http\JsonResponse; | ||
use Illuminate\Http\RedirectResponse; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Validation\Rules\Enum; | ||
|
||
class StatusController extends Controller | ||
{ | ||
|
||
public function updateStatus(Request $request): JsonResponse|RedirectResponse { | ||
$validated = $request->validate([ | ||
'statusId' => ['required', 'exists:statuses,id'], | ||
'body' => ['nullable', 'max:280'], | ||
'business_check' => ['required', new Enum(Business::class)], | ||
'checkinVisibility' => ['required', new Enum(StatusVisibility::class)], | ||
'destinationStopoverId' => ['nullable', 'exists:train_stopovers,id'], | ||
]); | ||
|
||
try { | ||
$status = Status::findOrFail($validated['statusId']); | ||
$this->authorize('update', $status); | ||
$status->update([ | ||
'body' => $validated['body'] ?? null, | ||
'business' => Business::from($validated['business_check']), | ||
'visibility' => StatusVisibility::from($validated['checkinVisibility']), | ||
]); | ||
|
||
if (isset($validated['destinationStopoverId']) | ||
&& $validated['destinationStopoverId'] != $status->trainCheckin->destination_stopover->id) { | ||
$pointReason = TrainCheckinController::changeDestination( | ||
checkin: $status->trainCheckin, | ||
newDestinationStopover: TrainStopover::findOrFail($validated['destinationStopoverId']), | ||
); | ||
$status->fresh(); | ||
|
||
return redirect()->route('statuses.get', ['id' => $status->id]) | ||
->with('checkin-success', [ | ||
'reason' => 'status-updated', | ||
'distance' => $status->trainCheckin->distance, | ||
'duration' => $status->trainCheckin->duration, | ||
'points' => $status->trainCheckin->points, | ||
'lineName' => $status->trainCheckin->HafasTrip->linename, | ||
'alsoOnThisConnection' => $status->trainCheckin->alsoOnThisConnection, | ||
'event' => $status->trainCheckin->event, | ||
'forced' => false, | ||
'pointsCalculationReason' => $pointReason, | ||
]); | ||
} | ||
|
||
return redirect()->route('statuses.get', ['id' => $status->id]) | ||
->with('success', __('status.update.success')); | ||
} catch (ModelNotFoundException|PermissionException) { | ||
return redirect()->back()->with('alert-danger', __('messages.exception.general')); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.