fix-ci #427

Merged
philipp merged 8 commits from fix-ci into staging 2024-04-24 07:20:56 +02:00
4 changed files with 44 additions and 7 deletions
Showing only changes of commit 9aefc814a7 - Show all commits

View File

@ -1,3 +1,5 @@
use std::collections::HashMap;
use crate::model::{boat::Boat, user::User}; use crate::model::{boat::Boat, user::User};
use chrono::NaiveDate; use chrono::NaiveDate;
use chrono::NaiveDateTime; use chrono::NaiveDateTime;
@ -24,7 +26,7 @@ pub struct BoatReservation {
#[derive(FromRow, Debug, Serialize, Deserialize)] #[derive(FromRow, Debug, Serialize, Deserialize)]
pub struct BoatReservationWithDetails { pub struct BoatReservationWithDetails {
#[serde(flatten)] #[serde(flatten)]
boat_reservation: BoatReservation, reservation: BoatReservation,
boat: Boat, boat: Boat,
user_applicant: User, user_applicant: User,
user_confirmation: Option<User>, user_confirmation: Option<User>,
@ -84,7 +86,7 @@ WHERE end_date >= CURRENT_DATE ORDER BY end_date
.unwrap(); .unwrap();
res.push(BoatReservationWithDetails { res.push(BoatReservationWithDetails {
boat_reservation: reservation, reservation,
boat, boat,
user_applicant, user_applicant,
user_confirmation, user_confirmation,
@ -92,6 +94,31 @@ WHERE end_date >= CURRENT_DATE ORDER BY end_date
} }
res 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( pub async fn create(
db: &SqlitePool, db: &SqlitePool,

View File

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

View File

@ -80,7 +80,10 @@ async fn index(
} }
context.insert("boats", &boats); context.insert("boats", &boats);
context.insert("reservations", &BoatReservation::all_future(db).await); context.insert(
"reservations",
&BoatReservation::all_future_with_groups(db).await,
);
context.insert("coxes", &coxes); context.insert("coxes", &coxes);
context.insert("users", &users); context.insert("users", &users);
context.insert("logtypes", &logtypes); context.insert("logtypes", &logtypes);
@ -171,7 +174,10 @@ async fn kiosk(
} }
context.insert("boats", &boats); context.insert("boats", &boats);
context.insert("reservations", &BoatReservation::all_future(db).await); context.insert(
"reservations",
&BoatReservation::all_future_with_groups(db).await,
);
context.insert("coxes", &coxes); context.insert("coxes", &coxes);
context.insert("users", &users); context.insert("users", &users);
context.insert("logtypes", &logtypes); context.insert("logtypes", &logtypes);

View File

@ -2,7 +2,8 @@
<div class="bg-white dark:bg-primary-900 rounded-md shadow pb-2 mt-3"> <div class="bg-white dark:bg-primary-900 rounded-md shadow pb-2 mt-3">
<h2 class="h2">Reservierungen ({{ reservations | length }})</h2> <h2 class="h2">Reservierungen ({{ reservations | length }})</h2>
<div class="grid grid-cols-1 gap-3 mb-3 w-full"> <div class="grid grid-cols-1 gap-3 mb-3 w-full">
{% for reservation in reservations %} {% for _, reservations_for_event in reservations %}
{% set reservation = reservations_for_event[0] %}
<div class="pt-2 px-3 border-t text-primary-900 dark:text-white"> <div class="pt-2 px-3 border-t text-primary-900 dark:text-white">
<strong class="block"> <strong class="block">
{{ reservation.start_date | date(format="%d.%m.%Y") }} {{ reservation.start_date | date(format="%d.%m.%Y") }}
@ -13,7 +14,10 @@
<small>({{ reservation.time_desc }})</small> <small>({{ reservation.time_desc }})</small>
</strong> </strong>
<span class="block"> <span class="block">
{{ reservation.boat.name }} {% for reservation in reservations_for_event %}
{{ reservation.boat.name }}
{% if not loop.last %}+{% endif %}
{% endfor %}
<small>({{ reservation.user_applicant.name }})</small> <small>({{ reservation.user_applicant.name }})</small>
</span> </span>
<span class="text-sm italic">{{ reservation.usage }}</span> <span class="text-sm italic">{{ reservation.usage }}</span>