only one place to 'calculate' the name
This commit is contained in:
@@ -45,9 +45,9 @@ async fn index(State(backend): State<Arc<Backend>>, cookies: CookieJar) -> Respo
|
||||
span.font-headline.rank.text-muted {
|
||||
(rank.rank)"."
|
||||
}
|
||||
@if rank.uuid == client.uuid { (PreEscaped("<mark>")) }
|
||||
(rank.name)
|
||||
@if rank.uuid == client.uuid { (PreEscaped("</mark>")) }
|
||||
@if rank.client == client { (PreEscaped("<mark>")) }
|
||||
(rank.client.get_display_name())
|
||||
@if rank.client == client{ (PreEscaped("</mark>")) }
|
||||
}
|
||||
span.font-headline.cam {
|
||||
(rank.amount)(PreEscaped(" "))"📸"
|
||||
|
@@ -9,6 +9,12 @@ pub struct Client {
|
||||
pub name: Option<String>,
|
||||
}
|
||||
|
||||
impl PartialEq for Client {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.uuid == other.uuid
|
||||
}
|
||||
}
|
||||
|
||||
impl Client {
|
||||
pub(crate) fn get_display_name(&self) -> String {
|
||||
match &self.name {
|
||||
|
@@ -1,40 +1,16 @@
|
||||
use crate::{random_names::get_name_by_uuid, Backend};
|
||||
|
||||
struct RankDb {
|
||||
pub(crate) rank: i64,
|
||||
pub(crate) name: Option<String>,
|
||||
pub(crate) uuid: String,
|
||||
pub(crate) amount: i64,
|
||||
}
|
||||
use crate::{model::client::Client, Backend};
|
||||
|
||||
pub(crate) struct Rank {
|
||||
pub(crate) rank: i64,
|
||||
pub(crate) name: String,
|
||||
pub(crate) uuid: String,
|
||||
pub(crate) client: Client,
|
||||
pub(crate) amount: i64,
|
||||
}
|
||||
|
||||
impl From<RankDb> for Rank {
|
||||
fn from(value: RankDb) -> Self {
|
||||
let name = match value.name {
|
||||
Some(name) => name,
|
||||
None => get_name_by_uuid(&value.uuid).to_string(),
|
||||
};
|
||||
|
||||
Self {
|
||||
rank: value.rank,
|
||||
name,
|
||||
uuid: value.uuid,
|
||||
amount: value.amount,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Backend {
|
||||
pub(crate) async fn highscore(&self) -> Vec<Rank> {
|
||||
match self {
|
||||
Backend::Sqlite(db) => sqlx::query_as!(
|
||||
RankDb,
|
||||
Backend::Sqlite(db) => {
|
||||
let rows = sqlx::query!(
|
||||
"SELECT
|
||||
RANK() OVER (ORDER BY COUNT(s.client_uuid) DESC) as rank,
|
||||
c.name,
|
||||
@@ -47,10 +23,20 @@ impl Backend {
|
||||
)
|
||||
.fetch_all(db)
|
||||
.await
|
||||
.unwrap_or_default()
|
||||
.into_iter()
|
||||
.unwrap_or_default();
|
||||
|
||||
rows.into_iter()
|
||||
.map(|row| Rank {
|
||||
rank: row.rank,
|
||||
client: Client {
|
||||
uuid: row.uuid,
|
||||
name: row.name,
|
||||
},
|
||||
amount: row.amount,
|
||||
})
|
||||
.map(|r| r.into())
|
||||
.collect(),
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user