From 034f40963ca7d9d9594f7cf7975f2b9536dd0105 Mon Sep 17 00:00:00 2001 From: Jonni Liljamo Date: Fri, 10 Feb 2023 14:07:57 +0200 Subject: [PATCH] feat(sdbclient): adhere to new API responses --- sdbclient/src/api/game/types.rs | 8 ++++++-- sdbclient/src/api/user/mod.rs | 13 ++++--------- sdbclient/src/api/user/types.rs | 17 +++++++++++++++++ .../src/plugins/menu/accountregister/mod.rs | 2 +- sdbclient/src/plugins/menu/play/ui.rs | 5 ++++- 5 files changed, 32 insertions(+), 13 deletions(-) create mode 100644 sdbclient/src/api/user/types.rs diff --git a/sdbclient/src/api/game/types.rs b/sdbclient/src/api/game/types.rs index 67828ef..517f025 100644 --- a/sdbclient/src/api/game/types.rs +++ b/sdbclient/src/api/game/types.rs @@ -8,13 +8,17 @@ use serde::{Deserialize, Serialize}; +use crate::api::user::types::UserPub; + #[derive(Debug, Serialize, Deserialize)] pub struct Game { pub id: String, pub created_at: String, pub updated_at: String, - pub p1: String, - pub p2: String, + pub host_id: String, + pub host: UserPub, + pub guest_id: String, + pub guest: UserPub, pub state: u8, pub ended_at: String, } diff --git a/sdbclient/src/api/user/mod.rs b/sdbclient/src/api/user/mod.rs index 0280410..3336e51 100644 --- a/sdbclient/src/api/user/mod.rs +++ b/sdbclient/src/api/user/mod.rs @@ -1,6 +1,6 @@ /* * This file is part of sdbclient - * Copyright (C) 2022 Jonni Liljamo + * Copyright (C) 2023 Jonni Liljamo * * Licensed under GPL-3.0-only. * See LICENSE for licensing information. @@ -11,6 +11,8 @@ use serde::{Deserialize, Serialize}; use super::APIErrorWrapper; +pub mod types; + #[derive(Serialize)] pub struct PostToken { pub email: String, @@ -49,18 +51,11 @@ pub struct PostRegister { pub password: String, } -#[derive(Debug, Serialize, Deserialize)] -pub struct ResultRegister { - pub id: String, - pub username: String, - pub email: String, -} - #[derive(Debug, Serialize, Deserialize)] #[serde(untagged)] pub enum ResponseRegister { Error(APIErrorWrapper), - Valid(ResultRegister), + Valid(types::UserPub), } pub fn register( diff --git a/sdbclient/src/api/user/types.rs b/sdbclient/src/api/user/types.rs new file mode 100644 index 0000000..94993b2 --- /dev/null +++ b/sdbclient/src/api/user/types.rs @@ -0,0 +1,17 @@ +/* + * This file is part of sdbclient + * Copyright (C) 2023 Jonni Liljamo + * + * Licensed under GPL-3.0-only. + * See LICENSE for licensing information. + */ + +use serde::{Deserialize, Serialize}; + +#[derive(Debug, Serialize, Deserialize)] +pub struct UserPub { + pub id: String, + pub created_at: String, + pub updated_at: String, + pub username: String, +} diff --git a/sdbclient/src/plugins/menu/accountregister/mod.rs b/sdbclient/src/plugins/menu/accountregister/mod.rs index ae00c32..b678eba 100644 --- a/sdbclient/src/plugins/menu/accountregister/mod.rs +++ b/sdbclient/src/plugins/menu/accountregister/mod.rs @@ -120,7 +120,7 @@ fn handle_register_call( user_token: token_res.token, id: register_res.id, username: register_res.username, - email: register_res.email, + email: inputs.email.clone(), }; save_event_writer.send(SaveEvent { diff --git a/sdbclient/src/plugins/menu/play/ui.rs b/sdbclient/src/plugins/menu/play/ui.rs index 8062237..dc15244 100644 --- a/sdbclient/src/plugins/menu/play/ui.rs +++ b/sdbclient/src/plugins/menu/play/ui.rs @@ -100,7 +100,10 @@ pub(super) fn show( .inner_margin(4.) .show(ui, |ui| { ui.horizontal(|ui| { - ui.label(format!("Host: {}", game.p1)); + ui.label(format!( + "Host: {}", + game.host.username + )); ui.with_layout( egui::Layout::right_to_left( egui::Align::Center, -- 2.44.1