Skip to content

Commit

Permalink
feat(tiers): add tierlists endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
uku3lig committed Dec 13, 2024
1 parent 477f7d6 commit 9ac3908
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/tiers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -66,6 +76,7 @@ struct MojangUUID {
pub fn router() -> Router<Arc<AppState>> {
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));

Expand Down Expand Up @@ -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::<HashMap<_, _>>();

Json(lists)
}

// === Utility functions ===

async fn fetch_tier(uuid: &Uuid) -> Option<PlayerInfo> {
Expand Down

0 comments on commit 9ac3908

Please sign in to comment.