2023-09-02 20:46:23 -04:00
|
|
|
use super::{PlayerId, QueryUnwrap};
|
|
|
|
use cynic::GraphQlResponse;
|
|
|
|
use schema::schema;
|
|
|
|
|
|
|
|
// Variables
|
|
|
|
|
2023-10-02 20:34:54 -04:00
|
|
|
#[derive(cynic::QueryVariables, Debug, Copy, Clone)]
|
2023-09-02 20:46:23 -04:00
|
|
|
pub struct PlayerInfoVars {
|
|
|
|
pub id: PlayerId,
|
|
|
|
}
|
|
|
|
|
|
|
|
// Query
|
|
|
|
|
|
|
|
#[derive(cynic::QueryFragment, Debug)]
|
|
|
|
#[cynic(graphql_type = "Query", variables = "PlayerInfoVars")]
|
|
|
|
pub struct PlayerInfo {
|
|
|
|
#[arguments(id: $id)]
|
|
|
|
player: Option<Player>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(cynic::QueryFragment, Debug)]
|
|
|
|
struct Player {
|
2023-09-23 02:35:24 -04:00
|
|
|
id: Option<PlayerId>,
|
2023-09-02 20:46:23 -04:00
|
|
|
gamer_tag: Option<String>,
|
|
|
|
prefix: Option<String>,
|
|
|
|
}
|
|
|
|
|
|
|
|
// Unwrapping
|
|
|
|
|
2023-09-23 02:35:24 -04:00
|
|
|
#[derive(Debug, Clone)]
|
2023-09-02 23:25:17 -04:00
|
|
|
pub struct PlayerData {
|
2023-09-23 02:35:24 -04:00
|
|
|
pub id: PlayerId,
|
2023-09-02 21:27:21 -04:00
|
|
|
pub name: Option<String>,
|
2023-09-02 20:46:23 -04:00
|
|
|
pub prefix: Option<String>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl QueryUnwrap<PlayerInfoVars> for PlayerInfo {
|
2023-09-02 23:25:17 -04:00
|
|
|
type Unwrapped = PlayerData;
|
2023-09-02 20:46:23 -04:00
|
|
|
|
2023-09-02 23:25:17 -04:00
|
|
|
fn unwrap_response(response: GraphQlResponse<PlayerInfo>) -> Option<PlayerData> {
|
2023-09-02 20:46:23 -04:00
|
|
|
let player = response.data?.player?;
|
2023-09-02 23:25:17 -04:00
|
|
|
Some(PlayerData {
|
2023-09-23 02:35:24 -04:00
|
|
|
id: player.id?,
|
2023-09-02 21:27:21 -04:00
|
|
|
name: player.gamer_tag,
|
2023-09-02 20:46:23 -04:00
|
|
|
prefix: player.prefix.filter(|pr| !pr.is_empty()),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|