From aba8bc774939b96a18e4e566ea766058d20a8271 Mon Sep 17 00:00:00 2001 From: philipp Date: Sun, 30 Jul 2023 20:21:59 +0200 Subject: [PATCH] add light damage --- src/model/boat.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/model/boat.rs b/src/model/boat.rs index 1e510eb..a5e30dc 100644 --- a/src/model/boat.rs +++ b/src/model/boat.rs @@ -79,6 +79,10 @@ impl Boat { sqlx::query!("SELECT * FROM boat_damage WHERE boat_id=? AND lock_boat=true AND user_id_verified is null", self.id).fetch_optional(db).await.unwrap().is_some() } + pub async fn has_minor_damage(&self, db: &SqlitePool) -> bool { + 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 on_water(&self, db: &SqlitePool) -> bool { sqlx::query!( "SELECT * FROM logbook WHERE boat_id=? AND arrival is null", @@ -105,10 +109,13 @@ ORDER BY amount_seats DESC let mut res = Vec::new(); for boat in boats { - let damage = match boat.is_locked(db).await { - true => BoatDamage::Locked, - false => BoatDamage::None, - }; + let mut damage = BoatDamage::None; + if boat.has_minor_damage(db).await { + damage = BoatDamage::Light; + } + if boat.is_locked(db).await { + damage = BoatDamage::Locked; + } res.push(BoatWithDetails { damage, on_water: boat.on_water(db).await,