Rework queries to be more convenient

This commit is contained in:
Kiana Sheibani 2023-09-23 02:35:24 -04:00
parent 6ce463b529
commit 847547c248
Signed by: toki
GPG key ID: 6CB106C25E86A9F7
3 changed files with 12 additions and 9 deletions

View file

@ -20,13 +20,16 @@ pub struct PlayerInfo {
#[derive(cynic::QueryFragment, Debug)]
struct Player {
id: Option<PlayerId>,
gamer_tag: Option<String>,
prefix: Option<String>,
}
// Unwrapping
#[derive(Debug, Clone)]
pub struct PlayerData {
pub id: PlayerId,
pub name: Option<String>,
pub prefix: Option<String>,
}
@ -37,6 +40,7 @@ impl QueryUnwrap<PlayerInfoVars> for PlayerInfo {
fn unwrap_response(response: GraphQlResponse<PlayerInfo>) -> Option<PlayerData> {
let player = response.data?.player?;
Some(PlayerData {
id: player.id?,
name: player.gamer_tag,
prefix: player.prefix.filter(|pr| !pr.is_empty()),
})

View file

@ -32,6 +32,7 @@ struct Videogame {
// Unwrapping
#[derive(Debug, Clone)]
pub struct VideogameData {
pub id: VideogameId,
pub name: String,

View file

@ -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<T> = Vec<Vec<T>>;
// Variables
#[derive(cynic::QueryVariables, Debug)]
@ -97,22 +99,18 @@ struct Player {
// Unwrap
#[derive(Debug, Clone)]
pub struct TournamentData {
pub name: String,
pub sets: Vec<SetData>,
}
#[derive(Debug, Clone)]
pub struct SetData {
pub teams: Vec<Vec<PlayerId>>,
pub teams: Teams<PlayerData>,
pub winner: usize,
}
pub struct PlayerData {
pub id: PlayerId,
pub gamer_tag: Option<String>,
pub prefix: Option<String>,
}
impl<'a> QueryUnwrap<TournamentSetsVars<'a>> for TournamentSets {
type Unwrapped = Vec<TournamentData>;
@ -154,7 +152,7 @@ impl<'a> QueryUnwrap<TournamentSetsVars<'a>> for TournamentSets {
let p_ = p.player?;
Some(PlayerData {
id: p_.id?,
gamer_tag: p_.gamer_tag,
name: p_.gamer_tag,
prefix: p_.prefix,
})
})