diff options
author | Ilion Beyst <ilion.beyst@gmail.com> | 2022-10-13 17:45:11 +0200 |
---|---|---|
committer | Ilion Beyst <ilion.beyst@gmail.com> | 2022-10-13 17:45:11 +0200 |
commit | 2278ecd2584050c28e62f0f5fd8967b81d64cc5b (patch) | |
tree | 20ec3117ba9a3c65c988d1d044d7539d0ec02a12 /planetwars-server/src/routes/matches.rs | |
parent | ce07419bbcff91631ade273cbfbed9808b5432e8 (diff) | |
download | planetwars.dev-2278ecd2584050c28e62f0f5fd8967b81d64cc5b.tar.xz planetwars.dev-2278ecd2584050c28e62f0f5fd8967b81d64cc5b.zip |
implement ListBotMatches, allow querying matches by bot/opponent pair
Diffstat (limited to 'planetwars-server/src/routes/matches.rs')
-rw-r--r-- | planetwars-server/src/routes/matches.rs | 13 |
1 files changed, 12 insertions, 1 deletions
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<NaiveDateTime>, bot: Option<String>, + opponent: Option<String>, outcome: Option<BotMatchOutcome>, } @@ -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 { |