fix multi-select; only show private boats owner + kiosk

This commit is contained in:
2023-09-24 22:17:28 +02:00
parent ce73fd8902
commit 09af9981df
4 changed files with 60 additions and 10 deletions

View File

@ -2,6 +2,8 @@ use rocket::serde::{Deserialize, Serialize};
use rocket::FromForm;
use sqlx::{FromRow, SqlitePool};
use super::user::User;
#[derive(FromRow, Debug, Serialize, Deserialize)]
pub struct Boat {
pub id: i64,
@ -130,6 +132,27 @@ ORDER BY amount_seats DESC
Self::boats_to_details(db, boats).await
}
pub async fn for_user(db: &SqlitePool, user: &User) -> Vec<BoatWithDetails> {
if user.is_admin {
return Self::all(db).await;
}
let boats = sqlx::query_as!(
Boat,
"
SELECT id, name, amount_seats, location_id, owner, year_built, boatbuilder, default_shipmaster_only_steering, skull, external
FROM boat
WHERE owner is null or owner = ?
ORDER BY amount_seats DESC
",
user.id
)
.fetch_all(db)
.await
.unwrap(); //TODO: fixme
Self::boats_to_details(db, boats).await
}
pub async fn all_at_location(db: &SqlitePool, location: String) -> Vec<BoatWithDetails> {
let boats = sqlx::query_as!(
Boat,