diff options
author | Birte Kristina Friesel <derf@finalrewind.org> | 2023-08-19 12:43:43 +0200 |
---|---|---|
committer | Birte Kristina Friesel <derf@finalrewind.org> | 2023-08-19 12:43:43 +0200 |
commit | b85e8a1e04b2021843f7fb11337bc5a298635b7b (patch) | |
tree | 67db7a85306b8a0d2f124a949f503459d0da6677 /lib/Travelynx/Controller/Api.pm | |
parent | 85022709d75940a3f84cdbe462f9b261b38fc69e (diff) |
API: Support HAFAS checkin (via journeyID)
Diffstat (limited to 'lib/Travelynx/Controller/Api.pm')
-rwxr-xr-x | lib/Travelynx/Controller/Api.pm | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/lib/Travelynx/Controller/Api.pm b/lib/Travelynx/Controller/Api.pm index 8ff98de..7f72a53 100755 --- a/lib/Travelynx/Controller/Api.pm +++ b/lib/Travelynx/Controller/Api.pm @@ -176,12 +176,14 @@ sub travel_v1 { my $from_station = sanitize( q{}, $payload->{fromStation} ); my $to_station = sanitize( q{}, $payload->{toStation} ); my $train_id; + my $hafas = exists $payload->{train}{journeyID} ? 1 : 0; if ( not( $from_station - and ( ( $payload->{train}{type} and $payload->{train}{no} ) - or $payload->{train}{id} ) + and ( ( $payload->{train}{type} and $payload->{train}{no} ) + or $payload->{train}{id} + or $payload->{train}{journeyID} ) ) ) { @@ -196,7 +198,7 @@ sub travel_v1 { return; } - if ( not $self->stations->search($from_station) ) { + if ( not $hafas and not $self->stations->search($from_station) ) { $self->render( json => { success => \0, @@ -208,7 +210,10 @@ sub travel_v1 { return; } - if ( $to_station and not $self->stations->search($to_station) ) { + if ( $to_station + and not $hafas + and not $self->stations->search($to_station) ) + { $self->render( json => { success => \0, @@ -222,7 +227,11 @@ sub travel_v1 { my $train_p; - if ( exists $payload->{train}{id} ) { + if ( exists $payload->{train}{journeyID} ) { + $train_p = Mojo::Promise->resolve( + sanitize( q{}, $payload->{train}{journeyID} ) ); + } + elsif ( exists $payload->{train}{id} ) { $train_p = Mojo::Promise->resolve( sanitize( 0, $payload->{train}{id} ) ); } |