Moved around types
All checks were successful
Release / build_release (push) Successful in 2m21s
Rust / build_and_test (push) Successful in 1m13s

This commit is contained in:
Lukas Wölfer
2026-01-17 22:24:00 +01:00
parent a2642f6b9a
commit b869842aa3
3 changed files with 58 additions and 64 deletions

View File

@@ -31,9 +31,4 @@ impl WsdcFetcher for ScoringDanceFetcher {
} }
/// Convenience alias for a shared, dynamic fetcher /// Convenience alias for a shared, dynamic fetcher
pub type DynWsdcFetcher = Arc<dyn WsdcFetcher>; pub type DynWsdcFetcher = Arc<dyn WsdcFetcher>;
/// Back-compat helper that uses the `WorldsdcFetcher`.
pub async fn fetch_wsdc_info(id: u32) -> Result<DanceInfo, DanceInfoError> {
WorldsdcFetcher.fetch(id).await
}

View File

@@ -1,5 +1,3 @@
use crate::dance_info::{CompState, DanceInfo, DanceRank, DanceRole};
#[derive(thiserror::Error, Debug)] #[derive(thiserror::Error, Debug)]
pub enum DanceInfoError { pub enum DanceInfoError {
#[error("Failed to build client: {0}")] #[error("Failed to build client: {0}")]
@@ -13,55 +11,3 @@ pub enum DanceInfoError {
#[error("Failed to parse html: {0}")] #[error("Failed to parse html: {0}")]
HtmlParse(#[from] super::scoringdance::ScoringParseError), 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<DanceInfoParser> 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,
}
}
}

View File

@@ -2,8 +2,8 @@ use std::collections::HashMap;
use crate::{ use crate::{
app_signature, app_signature,
dance_info::DanceInfo, dance_info::{CompState, DanceInfo, DanceRank, DanceRole},
fetching::{DanceInfoError, types::DanceInfoParser}, fetching::DanceInfoError,
}; };
use reqwest::ClientBuilder; use reqwest::ClientBuilder;
@@ -38,7 +38,8 @@ pub async fn fetch_wsdc_info_wsdc(id: u32) -> Result<DanceInfo, DanceInfoError>
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
#![allow(clippy::unwrap_used, reason = "Allow unwrap in tests")] #![allow(clippy::unwrap_used, reason = "Allow unwrap in tests")]
use crate::fetching::fetch_wsdc_info;
use super::fetch_wsdc_info_wsdc;
#[test] #[test]
#[ignore = "Only run when the mock api is setup"] #[ignore = "Only run when the mock api is setup"]
@@ -53,8 +54,60 @@ mod tests {
return; return;
} }
}; };
let x = rt.block_on(fetch_wsdc_info(7)); let x = rt.block_on(fetch_wsdc_info_wsdc(7));
dbg!(&x); dbg!(&x);
x.unwrap(); 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<DanceInfoParser> 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,
}
}
}