From 2576a463db327e8fdfbf225e91ec7b775bbcad39 Mon Sep 17 00:00:00 2001 From: Birte Kristina Friesel Date: Thu, 30 May 2024 11:25:52 +0200 Subject: [PATCH] perform stationinfo requests for hafas checkins --- lib/Travelynx.pm | 22 +++++++++++++++++++--- lib/Travelynx/Command/work.pm | 8 ++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/lib/Travelynx.pm b/lib/Travelynx.pm index f1f5ed3..c47f18e 100755 --- a/lib/Travelynx.pm +++ b/lib/Travelynx.pm @@ -508,6 +508,8 @@ sub startup { $self->add_route_timestamps( $uid, $train, 1 ); $self->add_wagonorder( $uid, 1, $train->train_id, $train->sched_departure, $train->train_no ); + $self->add_stationinfo( $uid, 1, $train->train_id, + $eva ); $self->run_hook( $uid, 'checkin' ); } @@ -636,6 +638,8 @@ sub startup { if ( $journey->class <= 16 ) { $self->app->add_wagonorder( $uid, 1, $journey->id, $found->sched_dep, $journey->number ); + $self->add_stationinfo( $uid, 1, $journey->id, + $found->loc->eva ); } } @@ -1000,6 +1004,8 @@ sub startup { $self->add_route_timestamps( $uid, $train, 0, 1 ); $self->add_wagonorder( $uid, 0, $train->train_id, $train->sched_departure, $train->train_no ); + $self->add_stationinfo( $uid, 0, $train->train_id, + $dep_eva, $new_checkout_station_id ); } $promise->resolve( 1, undef ); return; @@ -1477,9 +1483,19 @@ sub startup { return; } )->wait; + } + ); + $self->helper( + 'add_stationinfo' => sub { + my ( $self, $uid, $is_departure, $train_id, $dep_eva, $arr_eva ) + = @_; + + $uid //= $self->current_user->{id}; + + my $db = $self->pg->db; if ($is_departure) { - $self->dbdb->get_stationinfo_p( $in_transit->{dep_eva} )->then( + $self->dbdb->get_stationinfo_p($dep_eva)->then( sub { my ($station_info) = @_; my $data = { stationinfo_dep => $station_info }; @@ -1500,8 +1516,8 @@ sub startup { )->wait; } - if ( $in_transit->{arr_eva} and not $is_departure ) { - $self->dbdb->get_stationinfo_p( $in_transit->{arr_eva} )->then( + if ( $arr_eva and not $is_departure ) { + $self->dbdb->get_stationinfo_p($arr_eva)->then( sub { my ($station_info) = @_; my $data = { stationinfo_arr => $station_info }; diff --git a/lib/Travelynx/Command/work.pm b/lib/Travelynx/Command/work.pm index 5787c47..ac47085 100644 --- a/lib/Travelynx/Command/work.pm +++ b/lib/Travelynx/Command/work.pm @@ -73,6 +73,8 @@ sub run { { $self->app->add_wagonorder( $uid, 1, $train_id, $found_dep->sched_dep, $journey->number ); + $self->app->add_stationinfo( $uid, 1, $journey->id, + $found_dep->loc->eva ); } } @@ -89,6 +91,8 @@ sub run { { $self->app->add_wagonorder( $uid, 0, $train_id, $found_dep->sched_dep, $journey->number ); + $self->app->add_stationinfo( $uid, 0, $journey->id, + $found_dep->loc->eva, $found_arr->loc->eva ); } } } @@ -185,6 +189,8 @@ sub run { $self->app->add_route_timestamps( $uid, $train, 1 ); $self->app->add_wagonorder( $uid, 1, $train->train_id, $train->sched_departure, $train->train_no ); + $self->app->add_stationinfo( $uid, 1, $train->train_id, + $dep, $arr ); } } }; @@ -259,6 +265,8 @@ sub run { ); $self->app->add_wagonorder( $uid, 0, $train->train_id, $train->sched_departure, $train->train_no ); + $self->app->add_stationinfo( $uid, 0, $train->train_id, + $dep, $arr ); } } elsif ( $entry->{real_arr_ts} ) {