add prototype of highscore list
This commit is contained in:
20
src/game.rs
20
src/game.rs
@@ -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" }
|
||||||
|
@if rank.uuid == client.uuid { (PreEscaped("</mark>")) }
|
||||||
|
(PreEscaped("→"))
|
||||||
|
(rank.amount)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
p {
|
|
||||||
mark { "TODO: High score" }
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
28
src/model/highscore.rs
Normal file
28
src/model/highscore.rs
Normal 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(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -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;
|
||||||
|
Reference in New Issue
Block a user