From f429adb4f8607ef9b8b8e2c9fa3634c5f39a5602 Mon Sep 17 00:00:00 2001 From: Ilion Beyst Date: Sun, 30 Oct 2022 16:20:29 +0100 Subject: allow filtering map in bot matches --- planetwars-server/src/routes/matches.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'planetwars-server/src/routes/matches.rs') diff --git a/planetwars-server/src/routes/matches.rs b/planetwars-server/src/routes/matches.rs index 39c153d..1ae8c27 100644 --- a/planetwars-server/src/routes/matches.rs +++ b/planetwars-server/src/routes/matches.rs @@ -45,6 +45,7 @@ pub struct ListRecentMatchesParams { bot: Option, opponent: Option, + map: Option, had_errors: Option, outcome: Option, } @@ -72,6 +73,7 @@ pub async fn list_recent_matches( let matches_result = match params.bot { Some(bot_name) => { + // TODO: do we prefer BAD_REQUEST for invalid parameters, or do we want to return an empty response? let bot = db::bots::find_bot_by_name(&bot_name, &mut conn) .map_err(|_| StatusCode::BAD_REQUEST)?; @@ -83,9 +85,18 @@ pub async fn list_recent_matches( None }; + let map_id = if let Some(ref map_name) = params.map { + let map = db::maps::find_map_by_name(map_name, &mut conn) + .map_err(|_| StatusCode::BAD_REQUEST)?; + Some(map.id) + } else { + None + }; + matches::list_bot_matches( bot.id, opponent_id, + map_id, params.outcome, params.had_errors, count, -- cgit v1.2.3