diff --git a/src/fetching/mod.rs b/src/fetching/mod.rs index f6882a0..cefd904 100644 --- a/src/fetching/mod.rs +++ b/src/fetching/mod.rs @@ -31,9 +31,4 @@ impl WsdcFetcher for ScoringDanceFetcher { } /// Convenience alias for a shared, dynamic fetcher -pub type DynWsdcFetcher = Arc; - -/// Back-compat helper that uses the `WorldsdcFetcher`. -pub async fn fetch_wsdc_info(id: u32) -> Result { - WorldsdcFetcher.fetch(id).await -} +pub type DynWsdcFetcher = Arc; \ No newline at end of file diff --git a/src/fetching/types.rs b/src/fetching/types.rs index d623f06..57e130d 100644 --- a/src/fetching/types.rs +++ b/src/fetching/types.rs @@ -1,5 +1,3 @@ -use crate::dance_info::{CompState, DanceInfo, DanceRank, DanceRole}; - #[derive(thiserror::Error, Debug)] pub enum DanceInfoError { #[error("Failed to build client: {0}")] @@ -13,55 +11,3 @@ pub enum DanceInfoError { #[error("Failed to parse html: {0}")] HtmlParse(#[from] super::scoringdance::ScoringParseError), } - -#[derive(serde::Deserialize, Debug)] -enum OptionalDanceRank { - #[serde(rename = "N/A")] - NotAvailable, - #[serde(untagged)] - Rank(DanceRank), -} - -#[derive(serde::Deserialize, Debug)] -enum OptionalDancePoints { - #[serde(rename = "N/A")] - NotAvailable, - #[serde(untagged)] - Points(u16), -} - -#[derive(serde::Deserialize, Debug)] -pub struct DanceInfoParser { - pub dancer_first: String, - pub dancer_last: String, - pub short_dominate_role: DanceRole, - #[allow(dead_code)] - pub short_non_dominate_role: DanceRole, - pub dominate_role_highest_level_points: u16, - pub dominate_role_highest_level: DanceRank, - pub non_dominate_role_highest_level_points: OptionalDancePoints, - pub non_dominate_role_highest_level: OptionalDanceRank, -} - -impl From for DanceInfo { - fn from(value: DanceInfoParser) -> Self { - let non_dominant_role_comp = if let OptionalDanceRank::Rank(r) = - value.non_dominate_role_highest_level - && let OptionalDancePoints::Points(l) = value.non_dominate_role_highest_level_points - { - Some(CompState { rank: r, points: l }) - } else { - None - }; - Self { - firstname: value.dancer_first, - lastname: value.dancer_last, - dominant_role: value.short_dominate_role, - dominant_role_comp: CompState { - rank: value.dominate_role_highest_level, - points: value.dominate_role_highest_level_points, - }, - non_dominant_role_comp, - } - } -} diff --git a/src/fetching/worldsdc.rs b/src/fetching/worldsdc.rs index 6143ee8..d521069 100644 --- a/src/fetching/worldsdc.rs +++ b/src/fetching/worldsdc.rs @@ -2,8 +2,8 @@ use std::collections::HashMap; use crate::{ app_signature, - dance_info::DanceInfo, - fetching::{DanceInfoError, types::DanceInfoParser}, + dance_info::{CompState, DanceInfo, DanceRank, DanceRole}, + fetching::DanceInfoError, }; use reqwest::ClientBuilder; @@ -38,7 +38,8 @@ pub async fn fetch_wsdc_info_wsdc(id: u32) -> Result #[cfg(test)] mod tests { #![allow(clippy::unwrap_used, reason = "Allow unwrap in tests")] - use crate::fetching::fetch_wsdc_info; + + use super::fetch_wsdc_info_wsdc; #[test] #[ignore = "Only run when the mock api is setup"] @@ -53,8 +54,60 @@ mod tests { return; } }; - let x = rt.block_on(fetch_wsdc_info(7)); + let x = rt.block_on(fetch_wsdc_info_wsdc(7)); dbg!(&x); x.unwrap(); } } + +#[derive(serde::Deserialize, Debug)] +pub enum OptionalDanceRank { + #[serde(rename = "N/A")] + NotAvailable, + #[serde(untagged)] + Rank(DanceRank), +} + +#[derive(serde::Deserialize, Debug)] +pub enum OptionalDancePoints { + #[serde(rename = "N/A")] + NotAvailable, + #[serde(untagged)] + Points(u16), +} + +#[derive(serde::Deserialize, Debug)] +pub struct DanceInfoParser { + pub dancer_first: String, + pub dancer_last: String, + pub short_dominate_role: DanceRole, + #[allow(dead_code)] + pub short_non_dominate_role: DanceRole, + pub dominate_role_highest_level_points: u16, + pub dominate_role_highest_level: DanceRank, + pub non_dominate_role_highest_level_points: OptionalDancePoints, + pub non_dominate_role_highest_level: OptionalDanceRank, +} + +impl From for DanceInfo { + fn from(value: DanceInfoParser) -> Self { + let non_dominant_role_comp = if let OptionalDanceRank::Rank(r) = + value.non_dominate_role_highest_level + && let OptionalDancePoints::Points(l) = value.non_dominate_role_highest_level_points + { + Some(CompState { rank: r, points: l }) + } else { + None + }; + Self { + firstname: value.dancer_first, + lastname: value.dancer_last, + dominant_role: value.short_dominate_role, + dominant_role_comp: CompState { + rank: value.dominate_role_highest_level, + points: value.dominate_role_highest_level_points, + }, + non_dominant_role_comp, + } + } +}