Rename query response datatypes

This commit is contained in:
Kiana Sheibani 2023-09-02 23:25:17 -04:00
parent 326da19523
commit fe4f82daeb
Signed by: toki
GPG key ID: 6CB106C25E86A9F7
3 changed files with 15 additions and 19 deletions

View file

@ -26,17 +26,17 @@ struct Player {
// Unwrapping // Unwrapping
pub struct PlayerInfoResponse { pub struct PlayerData {
pub name: Option<String>, pub name: Option<String>,
pub prefix: Option<String>, pub prefix: Option<String>,
} }
impl QueryUnwrap<PlayerInfoVars> for PlayerInfo { impl QueryUnwrap<PlayerInfoVars> for PlayerInfo {
type Unwrapped = PlayerInfoResponse; type Unwrapped = PlayerData;
fn unwrap_response(response: GraphQlResponse<PlayerInfo>) -> Option<PlayerInfoResponse> { fn unwrap_response(response: GraphQlResponse<PlayerInfo>) -> Option<PlayerData> {
let player = response.data?.player?; let player = response.data?.player?;
Some(PlayerInfoResponse { Some(PlayerData {
name: player.gamer_tag, name: player.gamer_tag,
prefix: player.prefix.filter(|pr| !pr.is_empty()), prefix: player.prefix.filter(|pr| !pr.is_empty()),
}) })

View file

@ -32,17 +32,15 @@ struct Videogame {
// Unwrapping // Unwrapping
pub struct VideogameResponse { pub struct VideogameData {
pub id: VideogameId, pub id: VideogameId,
pub name: String, pub name: String,
} }
impl<'a> QueryUnwrap<VideogameSearchVars<'a>> for VideogameSearch { impl<'a> QueryUnwrap<VideogameSearchVars<'a>> for VideogameSearch {
type Unwrapped = Vec<VideogameResponse>; type Unwrapped = Vec<VideogameData>;
fn unwrap_response( fn unwrap_response(response: GraphQlResponse<VideogameSearch>) -> Option<Vec<VideogameData>> {
response: GraphQlResponse<VideogameSearch>,
) -> Option<Vec<VideogameResponse>> {
Some( Some(
response response
.data? .data?
@ -50,7 +48,7 @@ impl<'a> QueryUnwrap<VideogameSearchVars<'a>> for VideogameSearch {
.nodes .nodes
.into_iter() .into_iter()
.filter_map(|game| { .filter_map(|game| {
Some(VideogameResponse { Some(VideogameData {
id: game.id?, id: game.id?,
name: game.name?, name: game.name?,
}) })

View file

@ -95,23 +95,21 @@ struct Player {
// Unwrap // Unwrap
pub struct TournamentResponse { pub struct TournamentData {
pub name: String, pub name: String,
pub sets: Vec<SetResponse>, pub sets: Vec<SetData>,
} }
pub struct SetResponse { pub struct SetData {
pub teams: Vec<Vec<PlayerId>>, pub teams: Vec<Vec<PlayerId>>,
pub winner: usize, pub winner: usize,
} }
impl<'a> QueryUnwrap<TournamentSetsVars<'a>> for TournamentSets { impl<'a> QueryUnwrap<TournamentSetsVars<'a>> for TournamentSets {
type Unwrapped = Vec<TournamentResponse>; type Unwrapped = Vec<TournamentData>;
// This might be the most spaghetti code I've ever written // This might be the most spaghetti code I've ever written
fn unwrap_response( fn unwrap_response(response: GraphQlResponse<TournamentSets>) -> Option<Vec<TournamentData>> {
response: GraphQlResponse<TournamentSets>,
) -> Option<Vec<TournamentResponse>> {
Some( Some(
response response
.data? .data?
@ -148,14 +146,14 @@ impl<'a> QueryUnwrap<TournamentSetsVars<'a>> for TournamentSets {
.try_collect() .try_collect()
}) })
.try_collect()?; .try_collect()?;
Some(SetResponse { teams, winner }) Some(SetData { teams, winner })
}) })
.collect::<Vec<_>>(), .collect::<Vec<_>>(),
) )
}) })
.flatten() .flatten()
.collect(); .collect();
Some(TournamentResponse { Some(TournamentData {
name: tour.name?, name: tour.name?,
sets, sets,
}) })