From fe4f82daeb381051ed438eebfa1db1ac74770cfc Mon Sep 17 00:00:00 2001 From: Kiana Sheibani Date: Sat, 2 Sep 2023 23:25:17 -0400 Subject: [PATCH] Rename query response datatypes --- cli/src/queries/player_info.rs | 8 ++++---- cli/src/queries/search_games.rs | 10 ++++------ cli/src/queries/tournament_sets.rs | 16 +++++++--------- 3 files changed, 15 insertions(+), 19 deletions(-) diff --git a/cli/src/queries/player_info.rs b/cli/src/queries/player_info.rs index dbe5714..f2bc1f7 100644 --- a/cli/src/queries/player_info.rs +++ b/cli/src/queries/player_info.rs @@ -26,17 +26,17 @@ struct Player { // Unwrapping -pub struct PlayerInfoResponse { +pub struct PlayerData { pub name: Option, pub prefix: Option, } impl QueryUnwrap for PlayerInfo { - type Unwrapped = PlayerInfoResponse; + type Unwrapped = PlayerData; - fn unwrap_response(response: GraphQlResponse) -> Option { + fn unwrap_response(response: GraphQlResponse) -> Option { let player = response.data?.player?; - Some(PlayerInfoResponse { + Some(PlayerData { 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 7de64d7..d981515 100644 --- a/cli/src/queries/search_games.rs +++ b/cli/src/queries/search_games.rs @@ -32,17 +32,15 @@ struct Videogame { // Unwrapping -pub struct VideogameResponse { +pub struct VideogameData { pub id: VideogameId, pub name: String, } impl<'a> QueryUnwrap> for VideogameSearch { - type Unwrapped = Vec; + type Unwrapped = Vec; - fn unwrap_response( - response: GraphQlResponse, - ) -> Option> { + fn unwrap_response(response: GraphQlResponse) -> Option> { Some( response .data? @@ -50,7 +48,7 @@ impl<'a> QueryUnwrap> for VideogameSearch { .nodes .into_iter() .filter_map(|game| { - Some(VideogameResponse { + Some(VideogameData { id: game.id?, name: game.name?, }) diff --git a/cli/src/queries/tournament_sets.rs b/cli/src/queries/tournament_sets.rs index 74da022..ebe42d3 100644 --- a/cli/src/queries/tournament_sets.rs +++ b/cli/src/queries/tournament_sets.rs @@ -95,23 +95,21 @@ struct Player { // Unwrap -pub struct TournamentResponse { +pub struct TournamentData { pub name: String, - pub sets: Vec, + pub sets: Vec, } -pub struct SetResponse { +pub struct SetData { pub teams: Vec>, pub winner: usize, } impl<'a> QueryUnwrap> for TournamentSets { - type Unwrapped = Vec; + type Unwrapped = Vec; // This might be the most spaghetti code I've ever written - fn unwrap_response( - response: GraphQlResponse, - ) -> Option> { + fn unwrap_response(response: GraphQlResponse) -> Option> { Some( response .data? @@ -148,14 +146,14 @@ impl<'a> QueryUnwrap> for TournamentSets { .try_collect() }) .try_collect()?; - Some(SetResponse { teams, winner }) + Some(SetData { teams, winner }) }) .collect::>(), ) }) .flatten() .collect(); - Some(TournamentResponse { + Some(TournamentData { name: tour.name?, sets, })