feat(api/webhook): logging for journey recording, proper HTTP status codes
This commit is contained in:
@ -17,6 +17,7 @@ pub async fn get_railcar_identifier_by_journey(
|
||||
}
|
||||
|
||||
fn find_railcar_identifier(train_ordering: TrainOrdering) -> Result<u64, ResolveTripNumberError> {
|
||||
//TODO: refactor - trainsets can consist out of several trains
|
||||
let trainset = train_ordering.train_sets.first()
|
||||
.ok_or(ResolveTripNumberError::Api("No items in field 'fahrzeuggruppe'".to_string()))?;
|
||||
let identifier_str = trainset.identifier.to_owned();
|
||||
|
@ -7,7 +7,7 @@ use axum::{
|
||||
use axum_core::response::IntoResponse;
|
||||
use chrono::DateTime;
|
||||
use serde::Deserialize;
|
||||
use sqlx::PgPool;
|
||||
use sqlx::{Error, PgPool};
|
||||
use sqlx::postgres::PgQueryResult;
|
||||
use crate::api::db_vendo_navigator::get_railcar_identifier_by_journey;
|
||||
use crate::error::train_order_api_error::{CheckInError, ResolveTripNumberError};
|
||||
@ -46,14 +46,20 @@ async fn receive_travelynx_checkin(
|
||||
)
|
||||
.await
|
||||
.map_err(|e| CheckInError::from(e))?;
|
||||
let train = get_train_by_identifier(railcar_identifier as i32, db.clone())
|
||||
.await
|
||||
.map_err(|e| ResolveTripNumberError::from(e))
|
||||
.map_err(|e| CheckInError::from(e))?;
|
||||
let train_result = get_train_by_identifier(railcar_identifier as i32, db.clone())
|
||||
.await;
|
||||
let train = train_result
|
||||
.map_err(|e| {
|
||||
match e {
|
||||
Error::RowNotFound => CheckInError::TrainNotFound,
|
||||
e => CheckInError::from(ResolveTripNumberError::from(e))
|
||||
}
|
||||
})?;
|
||||
println!("Train: {:?}", train);
|
||||
record_journey(user, train, check_in.status.from_station.scheduled_time.unwrap(), db)
|
||||
let result = record_journey(user, train, check_in.status.from_station.scheduled_time.unwrap(), db)
|
||||
.await
|
||||
.expect("Failed to check in!");
|
||||
.map_err(|e| CheckInError::from(ResolveTripNumberError::from(e)))?;
|
||||
println!("Journey recorded: {:?}", result);
|
||||
let message = format!(
|
||||
"Successfully checked into {} {} ({}), departing from station {} at {}",
|
||||
check_in.status.train.train_type.unwrap(),
|
||||
@ -63,7 +69,7 @@ async fn receive_travelynx_checkin(
|
||||
check_in.status.from_station.scheduled_time.unwrap()
|
||||
);
|
||||
Ok::<_, CheckInError>((
|
||||
StatusCode::OK,
|
||||
StatusCode::CREATED,
|
||||
message
|
||||
).into_response())
|
||||
},
|
||||
|
Reference in New Issue
Block a user