aboutsummaryrefslogtreecommitdiff
path: root/planetwars-server/src/routes
diff options
context:
space:
mode:
authorIlion Beyst <ilion.beyst@gmail.com>2022-10-30 16:20:29 +0100
committerIlion Beyst <ilion.beyst@gmail.com>2022-10-30 16:23:35 +0100
commitf429adb4f8607ef9b8b8e2c9fa3634c5f39a5602 (patch)
treede4209bf4e00c01f70263deea148c56a8dd96436 /planetwars-server/src/routes
parent00d31df58d0ea68b11600d98ebf53150a2a0cb88 (diff)
downloadplanetwars.dev-f429adb4f8607ef9b8b8e2c9fa3634c5f39a5602.tar.xz
planetwars.dev-f429adb4f8607ef9b8b8e2c9fa3634c5f39a5602.zip
allow filtering map in bot matches
Diffstat (limited to 'planetwars-server/src/routes')
-rw-r--r--planetwars-server/src/routes/matches.rs11
1 files changed, 11 insertions, 0 deletions
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<String>,
opponent: Option<String>,
+ map: Option<String>,
had_errors: Option<bool>,
outcome: Option<BotMatchOutcome>,
}
@@ -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,