Rename query response datatypes
This commit is contained in:
parent
326da19523
commit
fe4f82daeb
|
@ -26,17 +26,17 @@ struct Player {
|
|||
|
||||
// Unwrapping
|
||||
|
||||
pub struct PlayerInfoResponse {
|
||||
pub struct PlayerData {
|
||||
pub name: Option<String>,
|
||||
pub prefix: Option<String>,
|
||||
}
|
||||
|
||||
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?;
|
||||
Some(PlayerInfoResponse {
|
||||
Some(PlayerData {
|
||||
name: player.gamer_tag,
|
||||
prefix: player.prefix.filter(|pr| !pr.is_empty()),
|
||||
})
|
||||
|
|
|
@ -32,17 +32,15 @@ struct Videogame {
|
|||
|
||||
// Unwrapping
|
||||
|
||||
pub struct VideogameResponse {
|
||||
pub struct VideogameData {
|
||||
pub id: VideogameId,
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
impl<'a> QueryUnwrap<VideogameSearchVars<'a>> for VideogameSearch {
|
||||
type Unwrapped = Vec<VideogameResponse>;
|
||||
type Unwrapped = Vec<VideogameData>;
|
||||
|
||||
fn unwrap_response(
|
||||
response: GraphQlResponse<VideogameSearch>,
|
||||
) -> Option<Vec<VideogameResponse>> {
|
||||
fn unwrap_response(response: GraphQlResponse<VideogameSearch>) -> Option<Vec<VideogameData>> {
|
||||
Some(
|
||||
response
|
||||
.data?
|
||||
|
@ -50,7 +48,7 @@ impl<'a> QueryUnwrap<VideogameSearchVars<'a>> for VideogameSearch {
|
|||
.nodes
|
||||
.into_iter()
|
||||
.filter_map(|game| {
|
||||
Some(VideogameResponse {
|
||||
Some(VideogameData {
|
||||
id: game.id?,
|
||||
name: game.name?,
|
||||
})
|
||||
|
|
|
@ -95,23 +95,21 @@ struct Player {
|
|||
|
||||
// Unwrap
|
||||
|
||||
pub struct TournamentResponse {
|
||||
pub struct TournamentData {
|
||||
pub name: String,
|
||||
pub sets: Vec<SetResponse>,
|
||||
pub sets: Vec<SetData>,
|
||||
}
|
||||
|
||||
pub struct SetResponse {
|
||||
pub struct SetData {
|
||||
pub teams: Vec<Vec<PlayerId>>,
|
||||
pub winner: usize,
|
||||
}
|
||||
|
||||
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
|
||||
fn unwrap_response(
|
||||
response: GraphQlResponse<TournamentSets>,
|
||||
) -> Option<Vec<TournamentResponse>> {
|
||||
fn unwrap_response(response: GraphQlResponse<TournamentSets>) -> Option<Vec<TournamentData>> {
|
||||
Some(
|
||||
response
|
||||
.data?
|
||||
|
@ -148,14 +146,14 @@ impl<'a> QueryUnwrap<TournamentSetsVars<'a>> for TournamentSets {
|
|||
.try_collect()
|
||||
})
|
||||
.try_collect()?;
|
||||
Some(SetResponse { teams, winner })
|
||||
Some(SetData { teams, winner })
|
||||
})
|
||||
.collect::<Vec<_>>(),
|
||||
)
|
||||
})
|
||||
.flatten()
|
||||
.collect();
|
||||
Some(TournamentResponse {
|
||||
Some(TournamentData {
|
||||
name: tour.name?,
|
||||
sets,
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue