rowt/src/model/mod.rs
philipp 9dc1ec6fa0
Some checks failed
CI/CD Pipeline / deploy-staging (push) Blocked by required conditions
CI/CD Pipeline / deploy-main (push) Blocked by required conditions
CI/CD Pipeline / test (push) Has been cancelled
add trailer reservation funcitonality; Fixes #443
2024-06-10 19:43:59 +02:00

79 lines
2.0 KiB
Rust

use chrono::NaiveDate;
use serde::Serialize;
use sqlx::SqlitePool;
use waterlevel::WaterlevelDay;
use self::{
event::{Event, EventWithUserAndTriptype},
trip::{Trip, TripWithUserAndType},
waterlevel::Waterlevel,
weather::Weather,
};
pub mod boat;
pub mod boatdamage;
pub mod boathouse;
pub mod boatreservation;
pub mod event;
pub mod family;
pub mod location;
pub mod log;
pub mod logbook;
pub mod logtype;
pub mod mail;
pub mod notification;
pub mod role;
pub mod rower;
pub mod stat;
pub mod trailer;
pub mod trailerreservation;
pub mod trip;
pub mod tripdetails;
pub mod triptype;
pub mod user;
pub mod usertrip;
pub mod waterlevel;
pub mod weather;
#[derive(Serialize, Debug)]
pub struct Day {
day: NaiveDate,
events: Vec<EventWithUserAndTriptype>,
trips: Vec<TripWithUserAndType>,
is_pinned: bool,
max_waterlevel: Option<WaterlevelDay>,
weather: Option<Weather>,
}
impl Day {
pub async fn new(db: &SqlitePool, day: NaiveDate, is_pinned: bool) -> Self {
if is_pinned {
Self {
day,
events: Event::get_pinned_for_day(db, day).await,
trips: Trip::get_pinned_for_day(db, day).await,
is_pinned,
max_waterlevel: Waterlevel::max_waterlevel_for_day(db, day).await,
weather: Weather::find_by_day(db, day).await,
}
} else {
Self {
day,
events: Event::get_for_day(db, day).await,
trips: Trip::get_for_day(db, day).await,
is_pinned,
max_waterlevel: Waterlevel::max_waterlevel_for_day(db, day).await,
weather: Weather::find_by_day(db, day).await,
}
}
}
pub async fn new_guest(db: &SqlitePool, day: NaiveDate, is_pinned: bool) -> Self {
let mut day = Self::new(db, day, is_pinned).await;
day.events.retain(|e| e.event.allow_guests);
day.trips.retain(|t| t.trip.allow_guests);
day
}
}