From 2278ecd2584050c28e62f0f5fd8967b81d64cc5b Mon Sep 17 00:00:00 2001 From: Ilion Beyst Date: Thu, 13 Oct 2022 17:45:11 +0200 Subject: implement ListBotMatches, allow querying matches by bot/opponent pair --- planetwars-server/src/routes/matches.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'planetwars-server/src/routes') diff --git a/planetwars-server/src/routes/matches.rs b/planetwars-server/src/routes/matches.rs index 3ad10cf..99c6d1a 100644 --- a/planetwars-server/src/routes/matches.rs +++ b/planetwars-server/src/routes/matches.rs @@ -42,6 +42,7 @@ pub struct ListRecentMatchesParams { after: Option, bot: Option, + opponent: Option, outcome: Option, } @@ -70,8 +71,18 @@ pub async fn list_recent_matches( Some(bot_name) => { let bot = db::bots::find_bot_by_name(&bot_name, &mut conn) .map_err(|_| StatusCode::BAD_REQUEST)?; + + let opponent_id = if let Some(opponent_name) = params.opponent { + let opponent = db::bots::find_bot_by_name(&opponent_name, &mut conn) + .map_err(|_| StatusCode::BAD_REQUEST)?; + Some(opponent.id) + } else { + None + }; + matches::list_bot_matches( bot.id, + opponent_id, params.outcome, count, params.before, @@ -82,7 +93,7 @@ pub async fn list_recent_matches( None => matches::list_public_matches(count, params.before, params.after, &mut conn), }; - let mut matches = matches_result.map_err(|_| StatusCode::BAD_REQUEST)?; + let mut matches = matches_result.expect("failed to get matches"); //.map_err(|_| StatusCode::BAD_REQUEST)?; let mut has_next = false; if matches.len() > requested_count { -- cgit v1.2.3