diff --git a/lobby/src/server.rs b/lobby/src/server.rs index 1b9e225f..ed5832c6 100644 --- a/lobby/src/server.rs +++ b/lobby/src/server.rs @@ -9,7 +9,7 @@ use rocket_contrib::json::Json; use serde_derive::Serialize; -use rocket::{get, routes}; +use rocket::{get, post, routes}; // this is just here for a POC. // TODO move those into their own file @@ -25,13 +25,27 @@ struct GameType { #[serde(rename_all = "camelCase")] struct Game { name: String, + #[serde(rename = "type")] type_: String, - id: u8, - max_users: u8, - user_count: u8, + id: u32, + max_users: u32, + user_count: u32, has_password: bool, } +#[derive(Debug, Serialize)] +#[serde(rename_all = "camelCase")] +struct TokenResponse { + username: String, + name: String, + user_count: u32, + max_users: u32, + has_password: bool, + #[serde(rename = "type")] + type_: String, + id: u32, +} + #[derive(Debug, Serialize)] #[serde(rename_all = "camelCase")] struct GameOverview { @@ -70,6 +84,27 @@ fn game_index() -> Json { Json(mock_data) } +#[post("/api/lobby/tokens/", format = "json")] +fn token_request(token: u32) -> Result, rocket::http::Status> { + if token != 42 { + return Err(rocket::http::Status::new( + 404, + "The requested Token is not valid", + )); + } + let mock_data = TokenResponse { + username: "Anonymous".into(), + name: "Rask".into(), + type_: "rask".into(), + id: 1, + max_users: 5, + user_count: 0, + has_password: true, + }; + + Ok(Json(mock_data)) +} + pub fn rocket() -> rocket::Rocket { let routes = routes![index, game_index]; rocket::ignite()