67 lines
1.6 KiB
Rust
67 lines
1.6 KiB
Rust
mod home;
|
|
mod list_groups;
|
|
|
|
pub use home::*;
|
|
use list_groups::ListGroups;
|
|
|
|
use gloo_net::http::Request;
|
|
use gloo_net::Error;
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
#[derive(Clone, Deserialize, Eq, PartialEq, Serialize)]
|
|
pub struct User {
|
|
id: String,
|
|
banned: bool,
|
|
blacklisted: bool,
|
|
experience: u32,
|
|
level: u32,
|
|
money: u32,
|
|
moneylimit: u32,
|
|
steamid: String,
|
|
discordid: String,
|
|
discordname: String,
|
|
}
|
|
|
|
#[derive(Default, Deserialize, Serialize)]
|
|
struct Game {
|
|
name: String,
|
|
}
|
|
|
|
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
|
|
pub struct Group {
|
|
pub id: String,
|
|
pub captain: String,
|
|
pub name: String,
|
|
pub game: String,
|
|
}
|
|
|
|
impl Group {
|
|
/// Change le champs `game` pour son nom et non son ID.
|
|
pub async fn get_game_name(&mut self) {
|
|
match Request::get(&format!("/api/games/{}", self.game))
|
|
.send()
|
|
.await
|
|
{
|
|
Ok(resp) => {
|
|
if resp.ok() {
|
|
let json: Result<Game, Error> = resp.json().await;
|
|
match json {
|
|
Ok(json) => self.game = json.name,
|
|
Err(err) => log::info!("{}", err.to_string()),
|
|
}
|
|
}
|
|
}
|
|
Err(_) => (),
|
|
}
|
|
}
|
|
|
|
/// Retourne l'id en BDD d'un jeu. None si le jeu n'existe pas.
|
|
pub async fn get_id_from_name(game: String) -> Option<String> {
|
|
match Request::get(&format!("/api/games/id?name={}", game)).send().await {
|
|
_ => ()
|
|
|
|
}
|
|
None
|
|
}
|
|
}
|