diff --git a/src/main.rs b/src/main.rs index 54ae841..6f88495 100644 --- a/src/main.rs +++ b/src/main.rs @@ -149,6 +149,32 @@ async fn get_territories( .body("{}") } +// Get the Territory info for a specific territory name? +#[get("/territories/{game_code}/{name}")] +async fn get_territory( + path: web::Path<(String, String)>, + games_actor: web::Data>, +) -> impl Responder { + let (game_code, name) = path.into_inner(); + if let Ok(Responses::GamesResult(games)) = games_actor.send(Messages::GetGames).await + && let Some(game) = games.iter().find(|g| g.code == *game_code) { + let territories = &game.territories; + for t in territories { + println!("Search term {name} vs. {0}", t.territory_name); + if t.territory_name == *name { + println!("{0:?}", t); + return HttpResponse::Ok() + .content_type("application/json") + .body(serde_json::to_string(&t).unwrap()); + } + } + } + HttpResponse::InternalServerError() + .content_type("application/json") + .body("{}") +} + + #[get("/geojson/{game_code}")] async fn geojson_endpoint( game_code: web::Path, @@ -173,7 +199,7 @@ async fn geojson_endpoint( async fn game_page(game_code: web::Path) -> impl Responder { let mut context = Context::new(); context.insert("game_code", game_code.as_str()); - let body = Tera::one_off(include_str!("templates/map.tera"), &context, false) + let body = Tera::one_off(include_str!("templates/map.html.tera"), &context, false) .expect("Failed to render template"); HttpResponse::Ok().body(body) } @@ -234,6 +260,7 @@ async fn main() -> std::io::Result<()> { .service(admin_query) .service(list_of_games) .service(get_territories) + .service(get_territory) }) .bind(("0.0.0.0", 8080))? .run() diff --git a/src/templates/map.html.tera b/src/templates/map.html.tera new file mode 100644 index 0000000..31b3983 --- /dev/null +++ b/src/templates/map.html.tera @@ -0,0 +1,90 @@ + + + + {{ game_code }} + + + + + +
+
    + + + \ No newline at end of file