Traewelling / traewelling

Free check-in service to log your public transit journeys
https://traewelling.de
GNU Affero General Public License v3.0
225 stars 43 forks source link

API: /trains/checkin only works after requesting /trains/trip #72

Closed derf closed 3 years ago

derf commented 3 years ago

Describe the bug Checking into a train using /trains/checkin and a valid tripID, start and stop station results in HTTP 500 unless a request to /trains/trip is sent first.

To Reproduce

curl  -X POST -H "Content-Type: application/json" -H "Authorization: Bearer ..." https://traewelling.de/api/v0/trains/checkin --data '{"tripID":...}'

-> HTTP 500 "Server Error"

curl  -H "Content-Type: application/json" -H "Authorization: Bearer ..." 'https://traewelling.de/api/v0/trains/trip?tripID=...&lineName=...&start=...'
curl  -X POST -H "Content-Type: application/json" -H "Authorization: Bearer ..." https://traewelling.de/api/v0/trains/checkin --data '{"tripID":...}'

-> works fine

Expected behavior /trains/checkin should work regardless of previous /trains/trip requests.

jeyemwey commented 3 years ago

This is likely a problem with TransportController::getHafasTrip. This function is called both by /trains/trip and /trains/checkin and requests the train data from the DB API, if it cannot find this train in the database. @HerrLevin, can you help why this is broken?

HerrLevin commented 3 years ago

Note to self: A similar behavior might occur with the TrainTrip-method while looking for a trainstation. This should also be addressed in future bugfixes.