[TASK] group reservations in log to avoid near-duplicates
All checks were successful
CI/CD Pipeline / test (push) Successful in 21m22s
CI/CD Pipeline / deploy-staging (push) Has been skipped
CI/CD Pipeline / deploy-main (push) Has been skipped

This commit is contained in:
2024-04-23 20:40:06 +02:00
parent 44c1b1bb72
commit 3abff08f61
4 changed files with 44 additions and 7 deletions

View File

@ -1,3 +1,5 @@
use std::collections::HashMap;
use crate::model::{boat::Boat, user::User};
use chrono::NaiveDate;
use chrono::NaiveDateTime;
@ -24,7 +26,7 @@ pub struct BoatReservation {
#[derive(FromRow, Debug, Serialize, Deserialize)]
pub struct BoatReservationWithDetails {
#[serde(flatten)]
boat_reservation: BoatReservation,
reservation: BoatReservation,
boat: Boat,
user_applicant: User,
user_confirmation: Option<User>,
@ -84,7 +86,7 @@ WHERE end_date >= CURRENT_DATE ORDER BY end_date
.unwrap();
res.push(BoatReservationWithDetails {
boat_reservation: reservation,
reservation,
boat,
user_applicant,
user_confirmation,
@ -92,6 +94,31 @@ WHERE end_date >= CURRENT_DATE ORDER BY end_date
}
res
}
pub async fn all_future_with_groups(
db: &SqlitePool,
) -> HashMap<String, Vec<BoatReservationWithDetails>> {
let mut grouped_reservations: HashMap<String, Vec<BoatReservationWithDetails>> =
HashMap::new();
let reservations = Self::all_future(db).await;
for reservation in reservations {
let key = format!(
"{}-{}-{}-{}-{}",
reservation.reservation.start_date,
reservation.reservation.end_date,
reservation.reservation.time_desc,
reservation.reservation.usage,
reservation.user_applicant.name
);
grouped_reservations
.entry(key)
.or_insert_with(Vec::new)
.push(reservation);
}
grouped_reservations
}
pub async fn create(
db: &SqlitePool,

View File

@ -26,7 +26,7 @@ const REGULAR: i32 = 22000;
const UNTERSTUETZEND: i32 = 2500;
const FOERDERND: i32 = 8500;
#[derive(FromRow, Serialize, Deserialize, Clone, Debug)]
#[derive(FromRow, Serialize, Deserialize, Clone, Debug, Eq, Hash)]
pub struct User {
pub id: i64,
pub name: String,