From cfc35fbec68845be805a795a4de5bae2081f3d7e Mon Sep 17 00:00:00 2001 From: philipp Date: Sat, 13 Apr 2024 09:42:12 +0200 Subject: [PATCH 1/2] only show non-placed boats in boathouse list --- src/model/boat.rs | 13 +++++++++++++ src/tera/board/boathouse.rs | 9 ++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/model/boat.rs b/src/model/boat.rs index d5d2494..f110b19 100644 --- a/src/model/boat.rs +++ b/src/model/boat.rs @@ -5,6 +5,8 @@ use rocket::serde::{Deserialize, Serialize}; use rocket::FromForm; use sqlx::{FromRow, Sqlite, SqlitePool, Transaction}; +use crate::model::boathouse::Boathouse; + use super::location::Location; use super::user::User; @@ -357,6 +359,17 @@ ORDER BY amount_seats DESC .await .unwrap(); //Okay, because we can only create a Boat of a valid id } + + pub async fn boathouse(&self, db: &SqlitePool) -> Option { + sqlx::query_as!( + Boathouse, + "SELECT * FROM boathouse WHERE boat_id like ?", + self.id + ) + .fetch_one(db) + .await + .ok() + } } #[cfg(test)] diff --git a/src/tera/board/boathouse.rs b/src/tera/board/boathouse.rs index 94119ba..e532f23 100644 --- a/src/tera/board/boathouse.rs +++ b/src/tera/board/boathouse.rs @@ -25,7 +25,14 @@ async fn index( } let boats = Boat::all_for_boatshouse(db).await; - context.insert("boats", &boats); + let mut final_boats = Vec::new(); + for boat in boats { + if boat.boat.boathouse(db).await.is_none() { + final_boats.push(boat); + } + } + + context.insert("boats", &final_boats); let boathouse = Boathouse::get(db).await; context.insert("boathouse", &boathouse); From 74d3957cf82df897eaac5c503d9a40f18bca44e2 Mon Sep 17 00:00:00 2001 From: philipp Date: Sat, 13 Apr 2024 09:44:22 +0200 Subject: [PATCH 2/2] dont show external boat --- src/tera/board/boathouse.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/tera/board/boathouse.rs b/src/tera/board/boathouse.rs index e532f23..e0336fd 100644 --- a/src/tera/board/boathouse.rs +++ b/src/tera/board/boathouse.rs @@ -28,7 +28,9 @@ async fn index( let mut final_boats = Vec::new(); for boat in boats { if boat.boat.boathouse(db).await.is_none() { - final_boats.push(boat); + if boat.boat.name != "Externes Boot" { + final_boats.push(boat); + } } }