From 9ac3908c9a8373a24c6a0c8ecd60d1aa1d7743d9 Mon Sep 17 00:00:00 2001 From: uku Date: Sat, 14 Dec 2024 00:20:43 +0100 Subject: [PATCH] feat(tiers): add tierlists endpoint --- src/tiers.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/tiers.rs b/src/tiers.rs index e65c077..f3d48e6 100644 --- a/src/tiers.rs +++ b/src/tiers.rs @@ -15,6 +15,16 @@ use crate::{AppState, RouteResponse}; const MCTIERS_REQS_KEY: &str = "api_rs_mctiers_reqs_total"; const MCTIERS_REQ_DURATION_KEY: &str = "api_rs_mctiers_req_duration_seconds"; +const TIERLISTS: [(&str, &str); 7] = [ + ("vanilla", "Vanilla"), + ("sword", "Sword"), + ("uhc", "UHC"), + ("pot", "Pot"), + ("neth_pot", "Netherite Pot"), + ("smp", "SMP"), + ("axe", "Axe"), +]; + #[derive(Debug, Clone, Default, Serialize, Deserialize)] pub struct PlayerInfo { pub uuid: Uuid, @@ -66,6 +76,7 @@ struct MojangUUID { pub fn router() -> Router> { let router = Router::new() .route("/all", get(get_all)) + .route("/tierlists", get(get_tierlists)) .route("/profile/:uuid", get(get_tier)) .route("/search_profile/:name", get(search_profile)); @@ -136,6 +147,23 @@ pub async fn search_profile( .map(IntoResponse::into_response) } +pub async fn get_tierlists() -> impl IntoResponse { + let lists = TIERLISTS + .iter() + .map(|(id, name)| { + let value = serde_json::json!({ + "title": name, + "info_text": "", + "kit_image": "", + }); + + (id, value) + }) + .collect::>(); + + Json(lists) +} + // === Utility functions === async fn fetch_tier(uuid: &Uuid) -> Option {