diff --git a/src/birch/route_info.rs b/src/birch/route_info.rs index 289873e..5133b17 100644 --- a/src/birch/route_info.rs +++ b/src/birch/route_info.rs @@ -2,6 +2,7 @@ use crate::CatenaryPostgresPool; use actix_web::web; use actix_web::HttpResponse; use actix_web::Responder; +use catenary::aspen::lib::ChateauMetadataEtcd; use catenary::aspen_dataset::AspenisedAlert; use catenary::models::DirectionPatternMeta; use catenary::models::DirectionPatternRow; @@ -21,6 +22,7 @@ use std::sync::Arc; use catenary::SerializableStop; use std::collections::HashMap; use std::collections::HashSet; +use tarpc::context; #[derive(Serialize, Deserialize, Clone)] pub struct RouteInfoResponse { @@ -77,7 +79,7 @@ pub async fn route_info( .body("Could not connect to etcd"); } - let etcd = etcd.unwrap(); + let mut etcd = etcd.unwrap(); //connect to postgres let conn_pool = pool.as_ref(); @@ -308,7 +310,50 @@ pub async fn route_info( //query realtime data pool for alerts - //TODO! + let fetch_assigned_node_for_this_chateau = etcd + .get( + format!("/aspen_assigned_chateaus/{}", &query.chateau).as_str(), + None, + ) + .await; + + let mut alerts_for_route_send: BTreeMap = BTreeMap::new(); + let mut alert_ids = vec![]; + + if let Ok(fetch_assigned_node_for_this_chateau) = fetch_assigned_node_for_this_chateau { + let fetch_assigned_node_for_this_chateau_kv_first = + fetch_assigned_node_for_this_chateau.kvs().first(); + + if let Some(fetch_assigned_node_for_this_chateau_data) = + fetch_assigned_node_for_this_chateau_kv_first + { + let assigned_chateau_data = bincode::deserialize::( + fetch_assigned_node_for_this_chateau_data.value(), + ) + .unwrap(); + + let aspen_client = + catenary::aspen::lib::spawn_aspen_client_from_ip(&assigned_chateau_data.socket) + .await; + + if let Ok(aspen_client) = aspen_client { + let alerts_for_route = aspen_client + .get_alerts_from_route_id( + context::current(), + query.chateau.clone(), + route.route_id.clone(), + ) + .await; + + if let Ok(Some(alerts_for_route)) = alerts_for_route { + for (alert_id, alert) in alerts_for_route { + alert_ids.push(alert_id.clone()); + alerts_for_route_send.insert(alert_id.clone(), alert); + } + } + } + } + } //return as struct //pdf is none for now @@ -352,8 +397,8 @@ pub async fn route_info( ) }) .collect(), - alert_ids_for_this_route: vec![], - alert_id_to_alert: BTreeMap::new(), + alert_ids_for_this_route: alert_ids, + alert_id_to_alert: alerts_for_route_send, }; HttpResponse::Ok().json(response) diff --git a/src/tile_save_and_get.rs b/src/tile_save_and_get.rs index fb30ecd..e4926b1 100644 --- a/src/tile_save_and_get.rs +++ b/src/tile_save_and_get.rs @@ -65,14 +65,15 @@ pub async fn delete_tile( Ok(()) } -pub async fn delete_in_bbox(conn: &mut bb8::PooledConnection<'_, AsyncDieselConnectionManager>, -category: TileCategory, -z: u8, -min_x: i32, -max_x: i32, -min_y: i32, -max_y: i32 -) -> Result<(), anyhow::Error> { +pub async fn delete_in_bbox( + conn: &mut bb8::PooledConnection<'_, AsyncDieselConnectionManager>, + category: TileCategory, + z: u8, + min_x: i32, + max_x: i32, + min_y: i32, + max_y: i32, +) -> Result<(), anyhow::Error> { let category_i16 = tile_enum_to_i16(category); let _ = diesel::delete( @@ -81,9 +82,9 @@ max_y: i32 .filter(crate::schema::gtfs::tile_storage::dsl::x.ge(min_x)) .filter(crate::schema::gtfs::tile_storage::dsl::x.le(max_x)) .filter(crate::schema::gtfs::tile_storage::dsl::y.ge(min_y)) - .filter(crate::schema::gtfs::tile_storage::dsl::y.le(max_y)) + .filter(crate::schema::gtfs::tile_storage::dsl::y.le(max_y)), ); - + Ok(()) }