Skip to content

Commit

Permalink
refactor list builds
Browse files Browse the repository at this point in the history
  • Loading branch information
cangzhang committed Jan 20, 2024
1 parent 0de47d2 commit 273884b
Showing 1 changed file with 10 additions and 18 deletions.
28 changes: 10 additions & 18 deletions crates/lcu/src/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,7 @@ pub struct ListBuildsResp {
pub content: Vec<builds::BuildSection>,
}

pub async fn list_builds_by_alias(
source: &String,
champion: &String,
) -> Result<Vec<builds::BuildSection>, FetchError> {
let url = format!("{SERVICE_URL}/api/source/{source}/champion-alias/{champion}");
pub async fn list_builds(url: &String) -> Result<Vec<builds::BuildSection>, FetchError> {
match reqwest::get(url).await {
Ok(resp) => match resp.json::<ListBuildsResp>().await {
Ok(resp) => Ok(resp.content),
Expand All @@ -125,24 +121,20 @@ pub async fn list_builds_by_alias(
}
}

pub async fn list_builds_by_alias(
source: &String,
champion: &String,
) -> Result<Vec<builds::BuildSection>, FetchError> {
let url = format!("{SERVICE_URL}/api/source/{source}/champion-alias/{champion}");
list_builds(&url).await
}

pub async fn list_builds_by_id(
source: &String,
champion_id: i64,
) -> Result<Vec<builds::BuildSection>, FetchError> {
let url = format!("{SERVICE_URL}/api/source/{source}/champion-id/{champion_id}");
match reqwest::get(url).await {
Ok(resp) => match resp.json::<ListBuildsResp>().await {
Ok(resp) => Ok(resp.content),
Err(e) => {
println!("list_builds_by_alias: {:?}", e);
Err(FetchError::Failed)
}
},
Err(err) => {
println!("fetch source list: {:?}", err);
Err(FetchError::Failed)
}
}
list_builds(&url).await
}

pub async fn fetch_champion_runes(
Expand Down

0 comments on commit 273884b

Please sign in to comment.