Skip to content
This repository has been archived by the owner on Mar 26, 2024. It is now read-only.

Commit

Permalink
Add dummy endpoint for /lobby/tokens/
Browse files Browse the repository at this point in the history
* rerename type_ to type
  • Loading branch information
TrueDoctor committed Jun 9, 2020
1 parent 3ec3c1e commit 3ec4452
Showing 1 changed file with 39 additions and 4 deletions.
43 changes: 39 additions & 4 deletions lobby/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -70,6 +84,27 @@ fn game_index() -> Json<GameOverview> {
Json(mock_data)
}

#[post("/api/lobby/tokens/<token>", format = "json")]
fn token_request(token: u32) -> Result<Json<TokenResponse>, 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()
Expand Down

0 comments on commit 3ec4452

Please sign in to comment.