From c0b6067d3409b4de6eeadbee19e51410e0da7021 Mon Sep 17 00:00:00 2001 From: Pierre Hubert Date: Mon, 12 Sep 2022 16:07:46 +0200 Subject: [PATCH] Reorganize routes --- src/human_player.rs | 7 ++++--- src/human_player_ws.rs | 2 +- src/main.rs | 12 +++--------- 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/human_player.rs b/src/human_player.rs index 14699d4..1478cdd 100644 --- a/src/human_player.rs +++ b/src/human_player.rs @@ -1,7 +1,7 @@ -use crate::data::GameRules; use actix::Addr; use uuid::Uuid; +use crate::data::GameRules; use crate::game::{Game, Player}; use crate::human_player_ws::{ClientMessage, HumanPlayerWS, ServerMessage}; @@ -22,8 +22,9 @@ impl Player for HumanPlayer { } fn query_boats_layout(&self, rules: &GameRules) { - self.player - .do_send(ServerMessage::QueryBoatsLayout(rules.clone())); + self.player.do_send(ServerMessage::QueryBoatsLayout { + rules: rules.clone(), + }); } } diff --git a/src/human_player_ws.rs b/src/human_player_ws.rs index ebaed78..0d31478 100644 --- a/src/human_player_ws.rs +++ b/src/human_player_ws.rs @@ -31,7 +31,7 @@ pub enum ClientMessage { #[serde(tag = "type")] pub enum ServerMessage { WaitingForOtherPlayer, - QueryBoatsLayout(GameRules), + QueryBoatsLayout { rules: GameRules }, } #[derive(Default)] diff --git a/src/main.rs b/src/main.rs index 98585c6..e458d1e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -31,7 +31,7 @@ async fn not_found() -> impl Responder { } /// Get bot configuration -async fn bot_configuration() -> impl Responder { +async fn game_configuration() -> impl Responder { HttpResponse::Ok().json(PlayConfiguration::default()) } @@ -54,11 +54,6 @@ async fn start_bot_play( resp } -/// Random play configuration -async fn random_play_config() -> impl Responder { - HttpResponse::Ok().json(GameRules::random_players_rules()) -} - #[actix_web::main] async fn main() -> std::io::Result<()> { env_logger::Builder::from_env(Env::default().default_filter_or("info")).init(); @@ -76,9 +71,8 @@ async fn main() -> std::io::Result<()> { App::new() .wrap(cors) - .route("/bot/config", web::get().to(bot_configuration)) - .route("/bot/play", web::get().to(start_bot_play)) - .route("/random/config", web::get().to(random_play_config)) + .route("/config", web::get().to(game_configuration)) + .route("/play/bot", web::get().to(start_bot_play)) .route("/", web::get().to(index)) .route("{tail:.*}", web::get().to(not_found)) })