reservations
This commit is contained in:
@ -36,9 +36,10 @@ pub enum BoatDamage {
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct BoatWithDetails {
|
||||
#[serde(flatten)]
|
||||
boat: Boat,
|
||||
pub(crate) boat: Boat,
|
||||
damage: BoatDamage,
|
||||
on_water: bool,
|
||||
reserved_today: bool,
|
||||
}
|
||||
|
||||
#[derive(FromForm)]
|
||||
@ -135,6 +136,20 @@ impl Boat {
|
||||
sqlx::query!("SELECT * FROM boat_damage WHERE boat_id=? AND lock_boat=false AND user_id_verified is null", self.id).fetch_optional(db).await.unwrap().is_some()
|
||||
}
|
||||
|
||||
pub async fn reserved_today(&self, db: &SqlitePool) -> bool {
|
||||
sqlx::query!(
|
||||
"SELECT *
|
||||
FROM boat_reservation
|
||||
WHERE boat_id =?
|
||||
AND date('now') BETWEEN start_date AND end_date;",
|
||||
self.id
|
||||
)
|
||||
.fetch_optional(db)
|
||||
.await
|
||||
.unwrap()
|
||||
.is_some()
|
||||
}
|
||||
|
||||
pub async fn on_water(&self, db: &SqlitePool) -> bool {
|
||||
sqlx::query!(
|
||||
"SELECT * FROM logbook WHERE boat_id=? AND arrival is null",
|
||||
@ -159,6 +174,7 @@ impl Boat {
|
||||
res.push(BoatWithDetails {
|
||||
damage,
|
||||
on_water: boat.on_water(db).await,
|
||||
reserved_today: boat.reserved_today(db).await,
|
||||
boat,
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user