From c7f4da07c1bb3b8a52a596e7c2573c7bf3ce7b79 Mon Sep 17 00:00:00 2001 From: Ilion Beyst Date: Sat, 12 Feb 2022 23:52:45 +0100 Subject: separate match data api from match log api --- planetwars-server/src/lib.rs | 6 +++++- planetwars-server/src/routes/matches.rs | 10 ++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) (limited to 'planetwars-server') diff --git a/planetwars-server/src/lib.rs b/planetwars-server/src/lib.rs index ccd5a02..94f2965 100644 --- a/planetwars-server/src/lib.rs +++ b/planetwars-server/src/lib.rs @@ -53,7 +53,11 @@ pub async fn api() -> Router { "/matches", get(routes::matches::list_matches).post(routes::matches::play_match), ) - .route("/matches/:match_id", get(routes::matches::get_match_log)) + .route("/matches/:match_id", get(routes::matches::get_match_data)) + .route( + "/matches/:match_id/log", + get(routes::matches::get_match_log), + ) .route("/submit_bot", post(routes::demo::submit_bot)) .layer(AddExtensionLayer::new(pool)); api diff --git a/planetwars-server/src/routes/matches.rs b/planetwars-server/src/routes/matches.rs index 089bd71..44c8607 100644 --- a/planetwars-server/src/routes/matches.rs +++ b/planetwars-server/src/routes/matches.rs @@ -136,6 +136,16 @@ pub struct BotConfig { pub build_command: Option, } +pub async fn get_match_data( + Path(match_id): Path, + conn: DatabaseConnection, +) -> Result, StatusCode> { + let match_data = matches::find_match(match_id, &conn) + .map_err(|_| StatusCode::NOT_FOUND) + .map(|data| match_data_to_api(data))?; + Ok(Json(match_data)) +} + pub async fn get_match_log( Path(match_id): Path, conn: DatabaseConnection, -- cgit v1.2.3