From 847547c24833f805bdfa46e33aeb50492affe20a Mon Sep 17 00:00:00 2001 From: Kiana Sheibani Date: Sat, 23 Sep 2023 02:35:24 -0400 Subject: [PATCH] Rework queries to be more convenient --- cli/src/queries/player_info.rs | 4 ++++ cli/src/queries/search_games.rs | 1 + cli/src/queries/tournament_sets.rs | 16 +++++++--------- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/cli/src/queries/player_info.rs b/cli/src/queries/player_info.rs index f2bc1f7..2966f08 100644 --- a/cli/src/queries/player_info.rs +++ b/cli/src/queries/player_info.rs @@ -20,13 +20,16 @@ pub struct PlayerInfo { #[derive(cynic::QueryFragment, Debug)] struct Player { + id: Option, gamer_tag: Option, prefix: Option, } // Unwrapping +#[derive(Debug, Clone)] pub struct PlayerData { + pub id: PlayerId, pub name: Option, pub prefix: Option, } @@ -37,6 +40,7 @@ impl QueryUnwrap for PlayerInfo { fn unwrap_response(response: GraphQlResponse) -> Option { let player = response.data?.player?; Some(PlayerData { + id: player.id?, name: player.gamer_tag, prefix: player.prefix.filter(|pr| !pr.is_empty()), }) diff --git a/cli/src/queries/search_games.rs b/cli/src/queries/search_games.rs index d981515..eec8e39 100644 --- a/cli/src/queries/search_games.rs +++ b/cli/src/queries/search_games.rs @@ -32,6 +32,7 @@ struct Videogame { // Unwrapping +#[derive(Debug, Clone)] pub struct VideogameData { pub id: VideogameId, pub name: String, diff --git a/cli/src/queries/tournament_sets.rs b/cli/src/queries/tournament_sets.rs index acaf413..9f81e76 100644 --- a/cli/src/queries/tournament_sets.rs +++ b/cli/src/queries/tournament_sets.rs @@ -1,7 +1,9 @@ -use super::{EntrantId, PlayerId, QueryUnwrap, Timestamp, VideogameId}; +use super::{EntrantId, PlayerData, PlayerId, QueryUnwrap, Timestamp, VideogameId}; use cynic::GraphQlResponse; use schema::schema; +pub type Teams = Vec>; + // Variables #[derive(cynic::QueryVariables, Debug)] @@ -97,22 +99,18 @@ struct Player { // Unwrap +#[derive(Debug, Clone)] pub struct TournamentData { pub name: String, pub sets: Vec, } +#[derive(Debug, Clone)] pub struct SetData { - pub teams: Vec>, + pub teams: Teams, pub winner: usize, } -pub struct PlayerData { - pub id: PlayerId, - pub gamer_tag: Option, - pub prefix: Option, -} - impl<'a> QueryUnwrap> for TournamentSets { type Unwrapped = Vec; @@ -154,7 +152,7 @@ impl<'a> QueryUnwrap> for TournamentSets { let p_ = p.player?; Some(PlayerData { id: p_.id?, - gamer_tag: p_.gamer_tag, + name: p_.gamer_tag, prefix: p_.prefix, }) })