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)] #[derive(cynic::QueryFragment, Debug)]
struct Player { struct Player {
id: Option<PlayerId>,
gamer_tag: Option<String>, gamer_tag: Option<String>,
prefix: Option<String>, prefix: Option<String>,
} }
// Unwrapping // Unwrapping
#[derive(Debug, Clone)]
pub struct PlayerData { pub struct PlayerData {
pub id: PlayerId,
pub name: Option<String>, pub name: Option<String>,
pub prefix: Option<String>, pub prefix: Option<String>,
} }
@ -37,6 +40,7 @@ impl QueryUnwrap<PlayerInfoVars> for PlayerInfo {
fn unwrap_response(response: GraphQlResponse<PlayerInfo>) -> Option<PlayerData> { fn unwrap_response(response: GraphQlResponse<PlayerInfo>) -> Option<PlayerData> {
let player = response.data?.player?; let player = response.data?.player?;
Some(PlayerData { Some(PlayerData {
id: player.id?,
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,6 +32,7 @@ struct Videogame {
// Unwrapping // Unwrapping
#[derive(Debug, Clone)]
pub struct VideogameData { pub struct VideogameData {
pub id: VideogameId, pub id: VideogameId,
pub name: String, 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 cynic::GraphQlResponse;
use schema::schema; use schema::schema;
pub type Teams<T> = Vec<Vec<T>>;
// Variables // Variables
#[derive(cynic::QueryVariables, Debug)] #[derive(cynic::QueryVariables, Debug)]
@ -97,22 +99,18 @@ struct Player {
// Unwrap // Unwrap
#[derive(Debug, Clone)]
pub struct TournamentData { pub struct TournamentData {
pub name: String, pub name: String,
pub sets: Vec<SetData>, pub sets: Vec<SetData>,
} }
#[derive(Debug, Clone)]
pub struct SetData { pub struct SetData {
pub teams: Vec<Vec<PlayerId>>, pub teams: Teams<PlayerData>,
pub winner: usize, 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 { impl<'a> QueryUnwrap<TournamentSetsVars<'a>> for TournamentSets {
type Unwrapped = Vec<TournamentData>; type Unwrapped = Vec<TournamentData>;
@ -154,7 +152,7 @@ impl<'a> QueryUnwrap<TournamentSetsVars<'a>> for TournamentSets {
let p_ = p.player?; let p_ = p.player?;
Some(PlayerData { Some(PlayerData {
id: p_.id?, id: p_.id?,
gamer_tag: p_.gamer_tag, name: p_.gamer_tag,
prefix: p_.prefix, prefix: p_.prefix,
}) })
}) })