forked from Ruderverein-Donau-Linz/rowt
allow filter for kiosk, to only show boats at specific location
This commit is contained in:
parent
6809a85749
commit
8a40dfe017
@ -94,19 +94,7 @@ impl Boat {
|
|||||||
.is_some()
|
.is_some()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn all(db: &SqlitePool) -> Vec<BoatWithDetails> {
|
async fn boats_to_details(db: &SqlitePool, boats: Vec<Boat>) -> Vec<BoatWithDetails> {
|
||||||
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
|
|
||||||
ORDER BY amount_seats DESC
|
|
||||||
"
|
|
||||||
)
|
|
||||||
.fetch_all(db)
|
|
||||||
.await
|
|
||||||
.unwrap(); //TODO: fixme
|
|
||||||
|
|
||||||
let mut res = Vec::new();
|
let mut res = Vec::new();
|
||||||
for boat in boats {
|
for boat in boats {
|
||||||
let mut damage = BoatDamage::None;
|
let mut damage = BoatDamage::None;
|
||||||
@ -125,6 +113,41 @@ ORDER BY amount_seats DESC
|
|||||||
res
|
res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn all(db: &SqlitePool) -> Vec<BoatWithDetails> {
|
||||||
|
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
|
||||||
|
ORDER BY amount_seats DESC
|
||||||
|
"
|
||||||
|
)
|
||||||
|
.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,
|
||||||
|
"
|
||||||
|
SELECT boat.id, boat.name, amount_seats, location_id, owner, year_built, boatbuilder, default_shipmaster_only_steering, skull, external
|
||||||
|
FROM boat
|
||||||
|
INNER JOIN location ON boat.location_id = location.id
|
||||||
|
WHERE location.name=?
|
||||||
|
ORDER BY amount_seats DESC
|
||||||
|
",
|
||||||
|
location
|
||||||
|
)
|
||||||
|
.fetch_all(db)
|
||||||
|
.await
|
||||||
|
.unwrap(); //TODO: fixme
|
||||||
|
|
||||||
|
Self::boats_to_details(db, boats).await
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn create(db: &SqlitePool, boat: BoatToAdd<'_>) -> Result<(), String> {
|
pub async fn create(db: &SqlitePool, boat: BoatToAdd<'_>) -> Result<(), String> {
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
"INSERT INTO boat(name, amount_seats, year_built, boatbuilder, default_shipmaster_only_steering, skull, external, location_id, owner) VALUES (?,?,?,?,?,?,?,?,?)",
|
"INSERT INTO boat(name, amount_seats, year_built, boatbuilder, default_shipmaster_only_steering, skull, external, location_id, owner) VALUES (?,?,?,?,?,?,?,?,?)",
|
||||||
|
@ -23,6 +23,21 @@ impl Location {
|
|||||||
.ok()
|
.ok()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn find_by_name(db: &SqlitePool, name: String) -> Option<Self> {
|
||||||
|
sqlx::query_as!(
|
||||||
|
Self,
|
||||||
|
"
|
||||||
|
SELECT id, name
|
||||||
|
FROM location
|
||||||
|
WHERE name=?
|
||||||
|
",
|
||||||
|
name
|
||||||
|
)
|
||||||
|
.fetch_one(db)
|
||||||
|
.await
|
||||||
|
.ok()
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn all(db: &SqlitePool) -> Vec<Self> {
|
pub async fn all(db: &SqlitePool) -> Vec<Self> {
|
||||||
sqlx::query_as!(Self, "SELECT id, name FROM location")
|
sqlx::query_as!(Self, "SELECT id, name FROM location")
|
||||||
.fetch_all(db)
|
.fetch_all(db)
|
||||||
|
@ -83,16 +83,17 @@ fn new_kiosk(cookies: &CookieJar<'_>) -> Redirect {
|
|||||||
let mut cookie = Cookie::new("kiosk", "yes".to_string());
|
let mut cookie = Cookie::new("kiosk", "yes".to_string());
|
||||||
cookie.set_expires(OffsetDateTime::now_utc() + Duration::weeks(12));
|
cookie.set_expires(OffsetDateTime::now_utc() + Duration::weeks(12));
|
||||||
cookies.add_private(cookie);
|
cookies.add_private(cookie);
|
||||||
Redirect::to("/log")
|
Redirect::to("/log/Linz")
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/")]
|
#[get("/<loc>")]
|
||||||
async fn kiosk(
|
async fn kiosk(
|
||||||
db: &State<SqlitePool>,
|
db: &State<SqlitePool>,
|
||||||
flash: Option<FlashMessage<'_>>,
|
flash: Option<FlashMessage<'_>>,
|
||||||
_kiosk: KioskCookie,
|
_kiosk: KioskCookie,
|
||||||
|
loc: String,
|
||||||
) -> Template {
|
) -> Template {
|
||||||
let boats = Boat::all(db).await;
|
let boats = Boat::all_at_location(db, loc).await;
|
||||||
let coxes = User::cox(db).await;
|
let coxes = User::cox(db).await;
|
||||||
let users = User::all(db).await;
|
let users = User::all(db).await;
|
||||||
let logtypes = LogType::all(db).await;
|
let logtypes = LogType::all(db).await;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user