allow filtering map in bot matches
This commit is contained in:
parent
00d31df58d
commit
f429adb4f8
3 changed files with 18 additions and 0 deletions
|
@ -12,6 +12,7 @@ pub struct ListBotMatches {
|
||||||
pub outcome: Option<BotMatchOutcome>,
|
pub outcome: Option<BotMatchOutcome>,
|
||||||
|
|
||||||
pub opponent_id: Option<i32>,
|
pub opponent_id: Option<i32>,
|
||||||
|
pub map_id: Option<i32>,
|
||||||
|
|
||||||
// pagination options
|
// pagination options
|
||||||
pub before: Option<NaiveDateTime>,
|
pub before: Option<NaiveDateTime>,
|
||||||
|
@ -55,6 +56,10 @@ impl QueryFragment<Pg> for ListBotMatches {
|
||||||
}
|
}
|
||||||
|
|
||||||
out.push_sql(" WHERE matches.state = 'finished' AND matches.is_public = true");
|
out.push_sql(" WHERE matches.state = 'finished' AND matches.is_public = true");
|
||||||
|
if let Some(map_id) = self.map_id.as_ref() {
|
||||||
|
out.push_sql(" AND matches.map_id = ");
|
||||||
|
out.push_bind_param::<Integer, _>(map_id)?;
|
||||||
|
}
|
||||||
if let Some(outcome) = self.outcome.as_ref() {
|
if let Some(outcome) = self.outcome.as_ref() {
|
||||||
match outcome {
|
match outcome {
|
||||||
BotMatchOutcome::Win => {
|
BotMatchOutcome::Win => {
|
||||||
|
|
|
@ -176,6 +176,7 @@ pub fn list_public_matches(
|
||||||
pub fn list_bot_matches(
|
pub fn list_bot_matches(
|
||||||
bot_id: i32,
|
bot_id: i32,
|
||||||
opponent_id: Option<i32>,
|
opponent_id: Option<i32>,
|
||||||
|
map_id: Option<i32>,
|
||||||
outcome: Option<BotMatchOutcome>,
|
outcome: Option<BotMatchOutcome>,
|
||||||
had_errors: Option<bool>,
|
had_errors: Option<bool>,
|
||||||
amount: i64,
|
amount: i64,
|
||||||
|
@ -188,6 +189,7 @@ pub fn list_bot_matches(
|
||||||
outcome,
|
outcome,
|
||||||
had_errors,
|
had_errors,
|
||||||
opponent_id,
|
opponent_id,
|
||||||
|
map_id,
|
||||||
before,
|
before,
|
||||||
after,
|
after,
|
||||||
amount,
|
amount,
|
||||||
|
|
|
@ -45,6 +45,7 @@ pub struct ListRecentMatchesParams {
|
||||||
|
|
||||||
bot: Option<String>,
|
bot: Option<String>,
|
||||||
opponent: Option<String>,
|
opponent: Option<String>,
|
||||||
|
map: Option<String>,
|
||||||
had_errors: Option<bool>,
|
had_errors: Option<bool>,
|
||||||
outcome: Option<BotMatchOutcome>,
|
outcome: Option<BotMatchOutcome>,
|
||||||
}
|
}
|
||||||
|
@ -72,6 +73,7 @@ pub async fn list_recent_matches(
|
||||||
|
|
||||||
let matches_result = match params.bot {
|
let matches_result = match params.bot {
|
||||||
Some(bot_name) => {
|
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)
|
let bot = db::bots::find_bot_by_name(&bot_name, &mut conn)
|
||||||
.map_err(|_| StatusCode::BAD_REQUEST)?;
|
.map_err(|_| StatusCode::BAD_REQUEST)?;
|
||||||
|
|
||||||
|
@ -83,9 +85,18 @@ pub async fn list_recent_matches(
|
||||||
None
|
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(
|
matches::list_bot_matches(
|
||||||
bot.id,
|
bot.id,
|
||||||
opponent_id,
|
opponent_id,
|
||||||
|
map_id,
|
||||||
params.outcome,
|
params.outcome,
|
||||||
params.had_errors,
|
params.had_errors,
|
||||||
count,
|
count,
|
||||||
|
|
Loading…
Reference in a new issue