add light damage

This commit is contained in:
philipp 2023-07-30 20:21:59 +02:00
parent d5033ccf44
commit aba8bc7749

View File

@ -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() 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 { pub async fn on_water(&self, db: &SqlitePool) -> bool {
sqlx::query!( sqlx::query!(
"SELECT * FROM logbook WHERE boat_id=? AND arrival is null", "SELECT * FROM logbook WHERE boat_id=? AND arrival is null",
@ -105,10 +109,13 @@ ORDER BY amount_seats DESC
let mut res = Vec::new(); let mut res = Vec::new();
for boat in boats { for boat in boats {
let damage = match boat.is_locked(db).await { let mut damage = BoatDamage::None;
true => BoatDamage::Locked, if boat.has_minor_damage(db).await {
false => BoatDamage::None, damage = BoatDamage::Light;
}; }
if boat.is_locked(db).await {
damage = BoatDamage::Locked;
}
res.push(BoatWithDetails { res.push(BoatWithDetails {
damage, damage,
on_water: boat.on_water(db).await, on_water: boat.on_water(db).await,