show boatreservations in planned
Some checks failed
CI/CD Pipeline / test (push) Has been cancelled
CI/CD Pipeline / deploy-staging (push) Has been cancelled
CI/CD Pipeline / deploy-main (push) Has been cancelled

This commit is contained in:
Philipp Hofer 2025-01-01 19:05:20 +01:00
parent d7187a7589
commit b560233acf
3 changed files with 79 additions and 4 deletions

View File

@ -56,6 +56,44 @@ impl BoatReservation {
.await .await
.ok() .ok()
} }
pub async fn for_day(db: &SqlitePool, day: NaiveDate) -> Vec<BoatReservationWithDetails> {
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<BoatReservationWithDetails> { pub async fn all_future(db: &SqlitePool) -> Vec<BoatReservationWithDetails> {
let boatreservations = sqlx::query_as!( let boatreservations = sqlx::query_as!(
@ -95,13 +133,13 @@ WHERE end_date >= CURRENT_DATE ORDER BY end_date
} }
res res
} }
pub async fn all_future_with_groups(
db: &SqlitePool, pub fn with_groups(
reservations: Vec<BoatReservationWithDetails>,
) -> HashMap<String, Vec<BoatReservationWithDetails>> { ) -> HashMap<String, Vec<BoatReservationWithDetails>> {
let mut grouped_reservations: HashMap<String, Vec<BoatReservationWithDetails>> = let mut grouped_reservations: HashMap<String, Vec<BoatReservationWithDetails>> =
HashMap::new(); HashMap::new();
let reservations = Self::all_future(db).await;
for reservation in reservations { for reservation in reservations {
let key = format!( let key = format!(
"{}-{}-{}-{}-{}", "{}-{}-{}-{}-{}",
@ -120,6 +158,12 @@ WHERE end_date >= CURRENT_DATE ORDER BY end_date
grouped_reservations grouped_reservations
} }
pub async fn all_future_with_groups(
db: &SqlitePool,
) -> HashMap<String, Vec<BoatReservationWithDetails>> {
let reservations = Self::all_future(db).await;
Self::with_groups(reservations)
}
pub async fn create( pub async fn create(
db: &SqlitePool, db: &SqlitePool,

View File

@ -11,6 +11,8 @@ use self::{
waterlevel::Waterlevel, waterlevel::Waterlevel,
weather::Weather, weather::Weather,
}; };
use boatreservation::{BoatReservation, BoatReservationWithDetails};
use std::collections::HashMap;
pub mod boat; pub mod boat;
pub mod boatdamage; pub mod boatdamage;
@ -48,6 +50,7 @@ pub struct Day {
regular_sees_this_day: bool, regular_sees_this_day: bool,
max_waterlevel: Option<WaterlevelDay>, max_waterlevel: Option<WaterlevelDay>,
weather: Option<Weather>, weather: Option<Weather>,
boat_reservations: HashMap<String, Vec<BoatReservationWithDetails>>,
} }
impl Day { impl Day {
@ -64,6 +67,9 @@ impl Day {
regular_sees_this_day, regular_sees_this_day,
max_waterlevel: Waterlevel::max_waterlevel_for_day(db, day).await, max_waterlevel: Waterlevel::max_waterlevel_for_day(db, day).await,
weather: Weather::find_by_day(db, day).await, weather: Weather::find_by_day(db, day).await,
boat_reservations: BoatReservation::with_groups(
BoatReservation::for_day(db, day).await,
),
} }
} else { } else {
Self { Self {
@ -74,6 +80,9 @@ impl Day {
regular_sees_this_day, regular_sees_this_day,
max_waterlevel: Waterlevel::max_waterlevel_for_day(db, day).await, max_waterlevel: Waterlevel::max_waterlevel_for_day(db, day).await,
weather: Weather::find_by_day(db, day).await, weather: Weather::find_by_day(db, day).await,
boat_reservations: BoatReservation::with_groups(
BoatReservation::for_day(db, day).await,
),
} }
} }
} }

View File

@ -89,8 +89,30 @@
</small> </small>
{% endif %} {% endif %}
</h2> </h2>
{% 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 %}
<div class="grid grid-cols-1 gap-3 mb-3"> <div class="grid grid-cols-1 gap-3 mb-3">
{# --- START Boatreservations--- #}
{% for _, reservations_for_event in day.boat_reservations %}
{% set reservation = reservations_for_event[0] %}
<div class="pt-2 px-3 {% if not loop.first %}border-t{% endif %} border-gray-200">
<div class="flex justify-between items-center">
<div class="mr-1">
<strong class="text-primary-900 dark:text-white">
Reservierung
{% for reservation in reservations_for_event -%}
{{ reservation.boat.name }}
{%- if not loop.last %} + {% endif -%}
{% endfor -%}
: {{ reservation.time_desc }}
</strong>
<small class="text-gray-600 dark:text-gray-100">(von {{ reservation.user_applicant.name }}, Grund: {{ reservation.usage}})</small>
<br />
</div>
</div>
</div>
{% endfor %}
{# --- END Boatreservations--- #}
{# --- START Events --- #} {# --- START Events --- #}
{% if day.events | length > 0 %} {% if day.events | length > 0 %}
{% for event in day.events | sort(attribute="planned_starting_time") %} {% for event in day.events | sort(attribute="planned_starting_time") %}