diff --git a/web/src/endpoints/export/get_events_data.rs b/web/src/endpoints/export/get_events_data.rs index 015d4afc..13498253 100644 --- a/web/src/endpoints/export/get_events_data.rs +++ b/web/src/endpoints/export/get_events_data.rs @@ -15,7 +15,7 @@ use crate::{ struct ExportQuery { start: NaiveDate, end: NaiveDate, - area: Option, + area: i32, } #[derive(PartialEq)] @@ -131,13 +131,16 @@ pub async fn get( return Err(ApplicationError::Unauthorized); } - let rows_to_export = ExportEventRow::read(pool.get_ref()).await?; + let rows_to_export = ExportEventRow::read_all_for_timerange_and_area( + pool.get_ref(), + (query.start, query.end), + query.area, + ) + .await?; let entries = read(rows_to_export); let mut workbook = Workbook::new(); let worksheet = workbook.add_worksheet(); - // let time_format = Format::new(); - // time_format.set_num_format(num_format) const HEADER: [&str; 10] = [ "Datum", diff --git a/web/src/models/export_event_row.rs b/web/src/models/export_event_row.rs index b5e46959..9230017b 100644 --- a/web/src/models/export_event_row.rs +++ b/web/src/models/export_event_row.rs @@ -1,4 +1,4 @@ -use chrono::NaiveDateTime; +use chrono::{NaiveDate, NaiveDateTime}; use sqlx::{ postgres::{PgHasArrayType, PgTypeInfo}, query, PgPool, @@ -34,7 +34,11 @@ impl PgHasArrayType for SimpleAssignment { } impl ExportEventRow { - pub async fn read(pool: &PgPool) -> Result, ApplicationError> { + pub async fn read_all_for_timerange_and_area( + pool: &PgPool, + time: (NaiveDate, NaiveDate), + area: i32, + ) -> Result, ApplicationError> { let rows = query!( "select event.starttimestamp, @@ -68,7 +72,11 @@ from event join location on event.locationId = location.id - order by event.starttimestamp" + where event.starttimestamp::date >= $1 and event.starttimestamp::date <= $2 and location.areaId = $3 + order by event.starttimestamp", + time.0, + time.1, + area ) .fetch_all(pool) .await?;