diff --git a/src/model/boatreservation.rs b/src/model/boatreservation.rs index 8a2a2b9..036dd21 100644 --- a/src/model/boatreservation.rs +++ b/src/model/boatreservation.rs @@ -56,6 +56,44 @@ impl BoatReservation { .await .ok() } + pub async fn for_day(db: &SqlitePool, day: NaiveDate) -> Vec { + let boatreservations = sqlx::query_as!( + Self, + " +SELECT id, boat_id, start_date, end_date, time_desc, usage, user_id_applicant, user_id_confirmation, created_at +FROM boat_reservation +WHERE end_date >= ? AND start_date <= ? + ", day, day + ) + .fetch_all(db) + .await + .unwrap(); //TODO: fixme + + let mut res = Vec::new(); + for reservation in boatreservations { + let user_confirmation = match reservation.user_id_confirmation { + Some(id) => { + let user = User::find_by_id(db, id as i32).await; + Some(user.unwrap()) + } + None => None, + }; + let user_applicant = User::find_by_id(db, reservation.user_id_applicant as i32) + .await + .unwrap(); + let boat = Boat::find_by_id(db, reservation.boat_id as i32) + .await + .unwrap(); + + res.push(BoatReservationWithDetails { + reservation, + boat, + user_applicant, + user_confirmation, + }); + } + res + } pub async fn all_future(db: &SqlitePool) -> Vec { let boatreservations = sqlx::query_as!( @@ -95,13 +133,13 @@ WHERE end_date >= CURRENT_DATE ORDER BY end_date } res } - pub async fn all_future_with_groups( - db: &SqlitePool, + + pub fn with_groups( + reservations: Vec, ) -> HashMap> { let mut grouped_reservations: HashMap> = HashMap::new(); - let reservations = Self::all_future(db).await; for reservation in reservations { let key = format!( "{}-{}-{}-{}-{}", @@ -120,6 +158,12 @@ WHERE end_date >= CURRENT_DATE ORDER BY end_date grouped_reservations } + pub async fn all_future_with_groups( + db: &SqlitePool, + ) -> HashMap> { + let reservations = Self::all_future(db).await; + Self::with_groups(reservations) + } pub async fn create( db: &SqlitePool, diff --git a/src/model/mod.rs b/src/model/mod.rs index 46446db..3a76436 100644 --- a/src/model/mod.rs +++ b/src/model/mod.rs @@ -11,6 +11,8 @@ use self::{ waterlevel::Waterlevel, weather::Weather, }; +use boatreservation::{BoatReservation, BoatReservationWithDetails}; +use std::collections::HashMap; pub mod boat; pub mod boatdamage; @@ -48,6 +50,7 @@ pub struct Day { regular_sees_this_day: bool, max_waterlevel: Option, weather: Option, + boat_reservations: HashMap>, } impl Day { @@ -64,6 +67,9 @@ impl Day { regular_sees_this_day, max_waterlevel: Waterlevel::max_waterlevel_for_day(db, day).await, weather: Weather::find_by_day(db, day).await, + boat_reservations: BoatReservation::with_groups( + BoatReservation::for_day(db, day).await, + ), } } else { Self { @@ -74,6 +80,9 @@ impl Day { regular_sees_this_day, max_waterlevel: Waterlevel::max_waterlevel_for_day(db, day).await, weather: Weather::find_by_day(db, day).await, + boat_reservations: BoatReservation::with_groups( + BoatReservation::for_day(db, day).await, + ), } } } diff --git a/templates/planned.html.tera b/templates/planned.html.tera index 02c328a..f4747e6 100644 --- a/templates/planned.html.tera +++ b/templates/planned.html.tera @@ -89,8 +89,30 @@ {% endif %} - {% if day.events | length > 0 or day.trips | length > 0 %} + {% if day.events | length > 0 or day.trips | length > 0 or day.boat_reservations | length > 0 %}
+ {# --- START Boatreservations--- #} + + {% for _, reservations_for_event in day.boat_reservations %} + {% set reservation = reservations_for_event[0] %} +
+
+
+ + Reservierung + {% for reservation in reservations_for_event -%} + {{ reservation.boat.name }} + {%- if not loop.last %} + {% endif -%} + {% endfor -%} + : {{ reservation.time_desc }} + + (von {{ reservation.user_applicant.name }}, Grund: {{ reservation.usage}}) +
+
+
+
+ {% endfor %} + {# --- END Boatreservations--- #} {# --- START Events --- #} {% if day.events | length > 0 %} {% for event in day.events | sort(attribute="planned_starting_time") %}