add prototype of highscore list

This commit is contained in:
2025-08-02 19:49:35 +02:00
parent 52da18bea6
commit 24697f5ffc
3 changed files with 43 additions and 8 deletions

View File

@@ -15,6 +15,7 @@ async fn index(State(backend): State<Arc<Backend>>, cookies: CookieJar) -> Respo
let sightings = backend.sightings_for_client(&client).await; let sightings = backend.sightings_for_client(&client).await;
let amount_total_cameras = backend.amount_total_cameras().await; let amount_total_cameras = backend.amount_total_cameras().await;
let highscore = backend.highscore().await;
let markup = new(html! { let markup = new(html! {
hgroup { hgroup {
@@ -29,15 +30,20 @@ async fn index(State(backend): State<Arc<Backend>>, cookies: CookieJar) -> Respo
p { p {
mark { "TODO: Show optional REGISTER-NAME message" } mark { "TODO: Show optional REGISTER-NAME message" }
} }
p { "You have found " (sightings.len()) "/" (amount_total_cameras) " cameras." }
p { p {
"You have found " h2 { "Highscore" }
(sightings.len()) ul {
"/" @for rank in highscore {
(amount_total_cameras) li {
" cameras." @if rank.uuid == client.uuid { (PreEscaped("<mark>")) }
} @if let Some(name) = rank.name { (name) } @else { "Anonymer Bär" }
p { @if rank.uuid == client.uuid { (PreEscaped("</mark>")) }
mark { "TODO: High score" } (PreEscaped("&rarr;"))
(rank.amount)
}
}
}
} }
}); });

28
src/model/highscore.rs Normal file
View File

@@ -0,0 +1,28 @@
use crate::Backend;
pub(crate) struct Rank {
pub(crate) name: Option<String>,
pub(crate) uuid: String,
pub(crate) amount: i64,
}
impl Backend {
pub(crate) async fn highscore(&self) -> Vec<Rank> {
match self {
Backend::Sqlite(db) => sqlx::query_as!(
Rank,
"SELECT
c.name,
c.uuid,
COUNT(s.client_uuid) as amount
FROM client c
LEFT JOIN sightings s ON c.uuid = s.client_uuid
GROUP BY c.uuid, c.name
ORDER BY amount DESC"
)
.fetch_all(db)
.await
.unwrap_or_default(),
}
}
}

View File

@@ -1,3 +1,4 @@
pub(crate) mod camera; pub(crate) mod camera;
pub(crate) mod client; pub(crate) mod client;
pub(crate) mod highscore;
pub(crate) mod sighting; pub(crate) mod sighting;