From b2c24df08a7329aca1c4ae13b2cc0683de063224 Mon Sep 17 00:00:00 2001 From: clerie Date: Sat, 27 Jul 2024 22:33:15 +0200 Subject: [PATCH] Filter departures only for trains that are generally not intended to be used on this connection --- src/main.rs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index fc58af1..54291f5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,6 +2,7 @@ use axum::{ extract::{ State, Path, + Query, }, http::StatusCode, response::Html, @@ -59,6 +60,10 @@ struct AppState { stations: HashMap, } +#[derive(Deserialize)] +struct RoutingQuery { + all: Option, +} #[tokio::main] async fn main() { @@ -175,7 +180,8 @@ async fn route_station_overview( async fn route_station_to_dest_station( State(state): State, - Path((station_id, dest_station_id)): Path<(String, String)> + Path((station_id, dest_station_id)): Path<(String, String)>, + query: Query, ) -> Result, (StatusCode, String)> { if !state.stations.contains_key(&station_id) { return Err((StatusCode::NOT_FOUND, String::from("Unknown departing station"))); @@ -216,9 +222,26 @@ async fn route_station_to_dest_station( out.push_str("\n"); out.push_str(&format!("

Abfahren für {} nach {}

\n", station_properties.name, dest_station_properties.name)); + + let display_all_departures = match query.all { + Some(_) => true, + None => false, + }; + + if display_all_departures { + out.push_str("Don't show all departures\n"); + } + else { + out.push_str("Show all departures\n"); + } + out.push_str("
    \n"); for departure in stationdata.departures { + if !display_all_departures && !vec![String::from("ICE"), String::from("IC"), String::from("EC")].contains(&departure.train.r#type) { + continue; + } + let departure_info = match departure.departure { Some(d) => d, None => continue,