summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBirte Kristina Friesel <derf@finalrewind.org>2023-07-23 12:21:37 +0200
committerBirte Kristina Friesel <derf@finalrewind.org>2023-07-23 12:21:37 +0200
commit13277ad770b6710a9a5536334011d04fcf390919 (patch)
tree8d065ea16afb6bd85cc9c23c04f533c9d7ba73b1
parentbe607983c14dfc260ec20e92b97265d016198040 (diff)
checkout: remove with_related special case
travelynx now always calls checkout with the database-provided arr_eva, so the edge case in which it provided a station that is not actually on the route of a train can no longer appear.
-rwxr-xr-xlib/Travelynx.pm47
-rwxr-xr-xlib/Travelynx/Controller/Api.pm19
2 files changed, 25 insertions, 41 deletions
diff --git a/lib/Travelynx.pm b/lib/Travelynx.pm
index f54bc14..469e1fe 100755
--- a/lib/Travelynx.pm
+++ b/lib/Travelynx.pm
@@ -591,16 +591,18 @@ sub startup {
'checkout' => sub {
my ( $self, %opt ) = @_;
- my $station = $opt{station};
- my $dep_eva = $opt{dep_eva};
- my $arr_eva = $opt{arr_eva};
- my $force = $opt{force};
- my $uid = $opt{uid};
- my $db = $opt{db} // $self->pg->db;
- my $status = $self->iris->get_departures(
- station => $station,
- lookbehind => 120,
- lookahead => 120
+ my $station = $opt{station};
+ my $dep_eva = $opt{dep_eva};
+ my $arr_eva = $opt{arr_eva};
+ my $with_related = $opt{with_related} // 0;
+ my $force = $opt{force};
+ my $uid = $opt{uid};
+ my $db = $opt{db} // $self->pg->db;
+ my $status = $self->iris->get_departures(
+ station => $station,
+ lookbehind => 120,
+ lookahead => 180,
+ with_related => $with_related,
);
$uid //= $self->current_user->{id};
my $user = $self->get_user_status( $uid, $db );
@@ -645,31 +647,6 @@ sub startup {
my $new_checkout_station_id = $status->{station_eva};
- # When a checkout is triggered by a checkin, there is an edge case
- # with related stations.
- # Assume a user travels from A to B1, then from B2 to C. B1 and B2 are
- # relatd stations (e.g. "Frankfurt Hbf" and "Frankfurt Hbf(tief)").
- # Now, if they check in for the journey from B2 to C, and have not yet
- # checked out of the previous train, $train is undef as B2 is not B1.
- # Redo the request with with_related => 1 to avoid this case.
- # While at it, we increase the lookahead to handle long journeys as
- # well.
- if ( not $train ) {
- $status = $self->iris->get_departures(
- station => $station,
- lookbehind => 120,
- lookahead => 180,
- with_related => 1
- );
- ($train) = List::Util::first { $_->train_id eq $train_id }
- @{ $status->{results} };
- if ( $train
- and $self->stations->get_by_eva( $train->station_uic ) )
- {
- $new_checkout_station_id = $train->station_uic;
- }
- }
-
# Store the intended checkout station regardless of this operation's
# success.
$self->in_transit->set_arrival_eva(
diff --git a/lib/Travelynx/Controller/Api.pm b/lib/Travelynx/Controller/Api.pm
index 9685582..d0ebc1b 100755
--- a/lib/Travelynx/Controller/Api.pm
+++ b/lib/Travelynx/Controller/Api.pm
@@ -277,10 +277,14 @@ sub travel_v1 {
);
}
if ($to_station) {
+
+ # the user may not have provided the correct to_station, so
+ # request related stations for checkout.
my ( $train2, $error ) = $self->checkout(
- station => $to_station,
- force => 0,
- uid => $uid
+ station => $to_station,
+ force => 0,
+ uid => $uid,
+ with_related => 1,
);
if ($error) {
return Mojo::Promise->reject($error);
@@ -330,10 +334,13 @@ sub travel_v1 {
);
}
+ # the user may not have provided the correct to_station, so
+ # request related stations for checkout.
my ( $train, $error ) = $self->checkout(
- station => $to_station,
- force => $payload->{force} ? 1 : 0,
- uid => $uid
+ station => $to_station,
+ force => $payload->{force} ? 1 : 0,
+ uid => $uid,
+ with_related => 1,
);
if ($error) {
$self->render(