feat: use filter for export

This commit is contained in:
Max Hohlfeld 2025-06-04 15:47:00 +02:00
parent d1e1ccd906
commit d8eb9ecbf3
2 changed files with 18 additions and 7 deletions

View File

@ -15,7 +15,7 @@ use crate::{
struct ExportQuery {
start: NaiveDate,
end: NaiveDate,
area: Option<i32>,
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",

View File

@ -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<Vec<ExportEventRow>, ApplicationError> {
pub async fn read_all_for_timerange_and_area(
pool: &PgPool,
time: (NaiveDate, NaiveDate),
area: i32,
) -> Result<Vec<ExportEventRow>, 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?;