From 0cda7295bee58e1a2965bc8c98b658028ccc7c8d Mon Sep 17 00:00:00 2001 From: Nicholas Orlowsky Date: Sun, 14 Sep 2025 11:38:35 -0400 Subject: [PATCH] fixed db queries --- api/src/database.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/api/src/database.rs b/api/src/database.rs index 86e72a2..2cd397d 100644 --- a/api/src/database.rs +++ b/api/src/database.rs @@ -97,6 +97,9 @@ pub async fn get_schedule_by_route_id( transaction: &mut Transaction<'_, Postgres>, ) -> ::anyhow::Result> { + let schedule_day = chrono::Utc::now().with_timezone(&chrono_tz::America::New_York); + let schedule_day_str = schedule_day.format("YYYYMMDD").to_string(); + let rows = sqlx::query!( r#"SELECT septa_stop_schedules.route_id, @@ -120,9 +123,10 @@ pub async fn get_schedule_by_route_id( WHERE septa_stop_schedules.route_id = $1 AND - service_id IN (SELECT service_id FROM septa_schedule_days WHERE date = '20250707') + service_id IN (SELECT service_id FROM septa_schedule_days WHERE date = $2) ;"#, - id + id, + schedule_day_str ) .fetch_all(&mut **transaction) .await?; @@ -223,6 +227,9 @@ pub async fn get_nta_by_stop_id( let start_secs = local_start.signed_duration_since(local_midnight).num_seconds(); let end_secs = local_end.signed_duration_since(local_midnight).num_seconds(); + let schedule_day = chrono::Utc::now().with_timezone(&chrono_tz::America::New_York); + let schedule_day_str = schedule_day.format("YYYYMMDD").to_string(); + let name_row = sqlx::query!("SELECT name FROM septa_stops WHERE id = $1", ids[0]).fetch_one(&mut **transaction).await?; let stop_name = name_row.name; @@ -251,7 +258,7 @@ pub async fn get_nta_by_stop_id( WHERE (septa_stops.id = $1 OR septa_stops.id = $2) AND - service_id IN (SELECT service_id FROM septa_schedule_days WHERE date = '20250707') + service_id IN (SELECT service_id FROM septa_schedule_days WHERE date = $5) AND septa_stop_schedules.arrival_time > $3 AND @@ -262,6 +269,7 @@ pub async fn get_nta_by_stop_id( .bind(&ids.get(1).unwrap_or(&0)) .bind(&start_secs) .bind(&end_secs) + .bind(&schedule_day_str) .fetch_all(&mut **transaction) .await?;