diff options
author | Ilion Beyst <ilion.beyst@gmail.com> | 2022-10-14 14:06:22 +0200 |
---|---|---|
committer | Ilion Beyst <ilion.beyst@gmail.com> | 2022-10-14 14:09:32 +0200 |
commit | b51b7a331ddfd93675e93d88cf267494b9c1b083 (patch) | |
tree | 9020aa8c536346285c1f429967e916f738c9e27c /planetwars-server/src/db/match_queries.rs | |
parent | 353ecd4c165042234e9f976b158bc970517940f5 (diff) | |
download | planetwars.dev-b51b7a331ddfd93675e93d88cf267494b9c1b083.tar.xz planetwars.dev-b51b7a331ddfd93675e93d88cf267494b9c1b083.zip |
allow filtering for had_errors
Diffstat (limited to 'planetwars-server/src/db/match_queries.rs')
-rw-r--r-- | planetwars-server/src/db/match_queries.rs | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/planetwars-server/src/db/match_queries.rs b/planetwars-server/src/db/match_queries.rs index 2e89706..999802f 100644 --- a/planetwars-server/src/db/match_queries.rs +++ b/planetwars-server/src/db/match_queries.rs @@ -8,9 +8,12 @@ use diesel::{PgConnection, QueryResult, RunQueryDsl}; pub struct ListBotMatches { pub bot_id: i32, - pub opponent_id: Option<i32>, + pub had_errors: Option<bool>, pub outcome: Option<BotMatchOutcome>, + pub opponent_id: Option<i32>, + + // pagination options pub before: Option<NaiveDateTime>, pub after: Option<NaiveDateTime>, pub amount: i64, @@ -29,6 +32,12 @@ impl QueryFragment<Pg> for ListBotMatches { "WHERE bot_id = " )); out.push_bind_param::<Integer, _>(&self.bot_id)?; + + if let Some(had_errors) = self.had_errors.as_ref() { + out.push_sql(" AND match_players.had_errors = "); + out.push_bind_param::<Bool, _>(had_errors)?; + } + out.push_sql(") main_player ON matches.id = main_player.match_id"); if let Some(opponent_id) = self.opponent_id.as_ref() { @@ -40,6 +49,7 @@ impl QueryFragment<Pg> for ListBotMatches { "WHERE bot_id = " )); out.push_bind_param::<Integer, _>(opponent_id)?; + out.push_sql(") other_player ON matches.id = other_player.match_id"); } |