cds-web/front/src/components/mod.rs

67 lines
1.6 KiB
Rust
Raw Normal View History

2022-10-28 16:57:08 +00:00
mod home;
mod list_groups;
pub use home::*;
use list_groups::ListGroups;
use gloo_net::http::Request;
2022-10-30 15:32:27 +00:00
use gloo_net::Error;
2022-10-28 16:57:08 +00:00
use serde::{Deserialize, Serialize};
2022-10-30 16:14:09 +00:00
#[derive(Clone, Deserialize, Eq, PartialEq, Serialize)]
2022-10-28 16:57:08 +00:00
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)]
2022-10-28 16:57:08 +00:00
struct Game {
name: String,
}
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
2022-10-28 16:57:08 +00:00
pub struct Group {
2022-10-29 21:07:29 +00:00
pub id: String,
pub captain: String,
2022-10-28 16:57:08 +00:00
pub name: String,
pub game: String,
}
impl Group {
/// Change le champs `game` pour son nom et non son ID.
2022-10-28 16:57:08 +00:00
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
}
2022-10-28 16:57:08 +00:00
}