diff options
author | Ilion Beyst <ilion.beyst@gmail.com> | 2022-08-04 21:48:25 +0200 |
---|---|---|
committer | Ilion Beyst <ilion.beyst@gmail.com> | 2022-08-04 21:48:25 +0200 |
commit | 3113f762d83fab020e63d008d1a6cbd15b441362 (patch) | |
tree | 2a78e0424f8724f95169331a29ad0c55300b4dbd /planetwars-server/src/routes/matches.rs | |
parent | 3c2f4977e478dc7c6b243cab540ac2de4d0e6c84 (diff) | |
download | planetwars.dev-3113f762d83fab020e63d008d1a6cbd15b441362.tar.xz planetwars.dev-3113f762d83fab020e63d008d1a6cbd15b441362.zip |
list matches for a specific bot
Diffstat (limited to 'planetwars-server/src/routes/matches.rs')
-rw-r--r-- | planetwars-server/src/routes/matches.rs | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/planetwars-server/src/routes/matches.rs b/planetwars-server/src/routes/matches.rs index fde8471..c1957d4 100644 --- a/planetwars-server/src/routes/matches.rs +++ b/planetwars-server/src/routes/matches.rs @@ -8,7 +8,10 @@ use serde::{Deserialize, Serialize}; use std::{path::PathBuf, sync::Arc}; use crate::{ - db::matches::{self, MatchState}, + db::{ + self, + matches::{self, MatchState}, + }, DatabaseConnection, GlobalConfig, }; @@ -35,6 +38,8 @@ pub struct ListRecentMatchesParams { // TODO: implement these before: Option<NaiveDateTime>, after: Option<NaiveDateTime>, + + bot: Option<String>, } const MAX_NUM_RETURNED_MATCHES: usize = 100; @@ -47,9 +52,18 @@ pub async fn list_recent_matches( let count = std::cmp::min( params.count.unwrap_or(DEFAULT_NUM_RETURNED_MATCHES), MAX_NUM_RETURNED_MATCHES, - ); + ) as i64; + + let matches = match params.bot { + Some(bot_name) => { + let bot = db::bots::find_bot_by_name(&bot_name, &conn) + .map_err(|_| StatusCode::BAD_REQUEST)?; + matches::list_bot_matches(bot.id, count, &conn) + } + None => matches::list_public_matches(count, &conn), + }; - matches::list_public_matches(count as i64, &conn) + matches .map_err(|_| StatusCode::BAD_REQUEST) .map(|matches| Json(matches.into_iter().map(match_data_to_api).collect())) } |