From 7ae60f2ea44aa61ed0d9451c4389b6d7630d583e Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Sat, 14 Dec 2019 23:46:36 +0100 Subject: [PATCH] Travel API: comment support --- lib/Travelynx.pm | 4 ++-- lib/Travelynx/Controller/Api.pm | 9 +++++++++ templates/api_documentation.html.ep | 6 ++++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/lib/Travelynx.pm b/lib/Travelynx.pm index def2d3d..73c221a 100755 --- a/lib/Travelynx.pm +++ b/lib/Travelynx.pm @@ -806,8 +806,8 @@ sub startup { $self->helper( 'update_in_transit_comment' => sub { - my ( $self, $comment ) = @_; - my $uid = $self->current_user->{id}; + my ( $self, $comment, $uid ) = @_; + $uid //= $self->current_user->{id}; my $status = $self->pg->db->select( 'in_transit', ['user_data'], { user_id => $uid } )->expand->hash; diff --git a/lib/Travelynx/Controller/Api.pm b/lib/Travelynx/Controller/Api.pm index f420a9e..2e1fa49 100755 --- a/lib/Travelynx/Controller/Api.pm +++ b/lib/Travelynx/Controller/Api.pm @@ -260,6 +260,10 @@ sub travel_v1 { my ( $train, $error ) = $self->checkin( $from_station, $train_id, $uid ); + if ( $payload->{comment} ) { + $self->update_in_transit_comment( + sanitize( q{}, $payload->{comment} ), $uid ); + } if ( $to_station and not $error ) { ( $train, $error ) = $self->checkout( $to_station, 0, $uid ); } @@ -284,6 +288,11 @@ sub travel_v1 { elsif ( $payload->{action} eq 'checkout' ) { my $to_station = sanitize( q{}, $payload->{toStation} ); + if ( $payload->{comment} ) { + $self->update_in_transit_comment( + sanitize( q{}, $payload->{comment} ), $uid ); + } + my ( $train, $error ) = $self->checkout( $to_station, $payload->{force} ? 1 : 0, $uid ); if ($error) { diff --git a/templates/api_documentation.html.ep b/templates/api_documentation.html.ep index b831e33..b9b7b44 100644 --- a/templates/api_documentation.html.ep +++ b/templates/api_documentation.html.ep @@ -85,7 +85,8 @@ "no" : "1234",
}
"fromStation" : "Essen Hbf", (DS100 oder EVA-Nummer sind ebenfalls möglich)
- "toStation" : "Berlin Hbf" (optional, DS100 oder EVA-Nummer sind ebenfalls möglich)
+ "toStation" : "Berlin Hbf", (optional, DS100 oder EVA-Nummer sind ebenfalls möglich)
+ "comment" : "Beliebiger Text" (optional)
}

Payload zur Wahl eines neuen Ziels, wenn bereits eingecheckt:

@@ -94,7 +95,8 @@ "token" : "<%= $uid %>-<%= $token->{import} // 'TOKEN' %>",
"action" : "checkout",
"force" : True/False, (wenn True: Checkout jetzt durchführen und auftretende Fehler ignorieren. Kann zu Logeinträgen ohne Ankunftsdaten führen.)
- "toStation" : "Berlin Hbf" (DS100 oder EVA-Nummer sind ebenfalls möglich)
+ "toStation" : "Berlin Hbf", (DS100 oder EVA-Nummer sind ebenfalls möglich)
+ "comment" : "Beliebiger Text" (optional)
}

Payload zum Rückgängigmachen eines Checkins (nur während der Fahrt möglich):