feat(api/webhook): logging for journey recording, proper HTTP status codes

This commit is contained in:
2025-05-11 13:41:52 +02:00
parent 41651dac21
commit 385ef7d833
5 changed files with 145 additions and 13 deletions

View File

@ -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())
},