From fa9672596812f7486ef06a0b64bdafb1178dc141 Mon Sep 17 00:00:00 2001 From: Kiana Sheibani Date: Mon, 28 Aug 2023 00:57:20 -0400 Subject: [PATCH] Write TournamentSets query test code --- cli/src/main.rs | 46 +++++++++++++++++++++++++++++----------------- cli/src/queries.rs | 2 ++ 2 files changed, 31 insertions(+), 17 deletions(-) diff --git a/cli/src/main.rs b/cli/src/main.rs index bf65597..1e43ba0 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -6,7 +6,6 @@ use std::path::Path; mod queries; use queries::*; -use search_games::{VideogameSearch, VideogameSearchVars}; mod datasets; @@ -20,9 +19,14 @@ fn get_auth_key(config_dir: &Path) -> Option { Err(VarError::NotPresent) => { let mut auth_file = config_dir.to_owned(); auth_file.push("auth.txt"); - read_to_string(auth_file) - .ok() - .and_then(|s| s.split_whitespace().next().map(String::from)) + read_to_string(auth_file).ok().and_then(|s| { + let trimmed = s.trim(); + if trimmed.is_empty() { + None + } else { + Some(trimmed.to_owned()) + } + }) } } } @@ -32,22 +36,30 @@ fn main() { config_dir.push("ggelo"); let auth_key = get_auth_key(&config_dir).expect("Could not find authorization key"); - // Get search prompt - let mut search = String::new(); - print!("Search for game: "); - let _ = io::stdout().flush(); - io::stdin() - .read_line(&mut search) - .expect("Error reading from stdin"); - - if let Some(response) = block_on(run_query::( - VideogameSearchVars { name: &search }, + if let Some(response) = block_on(run_query::( + TournamentSetsVars { + last_query: None, + game_id: VideogameId(1386), + country: None, + state: Some("GA"), + }, &auth_key, )) { - for game in response.into_iter() { - println!("{} - {}", game.id.0, game.name); + println!("Succeeded"); + for tournament in response { + println!("Tournament: {}", tournament.name); + for set in tournament.sets { + println!( + "Winner: {}", + if set.winner { + set.player2.0 + } else { + set.player1.0 + } + ); + } } } else { - println!("No response"); + println!("Invalid GraphQL response"); } } diff --git a/cli/src/queries.rs b/cli/src/queries.rs index 2e9497a..669498f 100644 --- a/cli/src/queries.rs +++ b/cli/src/queries.rs @@ -2,7 +2,9 @@ use cynic::{GraphQlResponse, QueryBuilder}; use serde::{Deserialize, Serialize}; pub mod search_games; +pub use search_games::*; pub mod tournament_sets; +pub use tournament_sets::*; use schema::schema;