aboutsummaryrefslogtreecommitdiff
path: root/planetwars-server/src/db/matches.rs
diff options
context:
space:
mode:
authorIlion Beyst <ilion.beyst@gmail.com>2022-08-04 21:48:25 +0200
committerIlion Beyst <ilion.beyst@gmail.com>2022-08-04 21:48:25 +0200
commit3113f762d83fab020e63d008d1a6cbd15b441362 (patch)
tree2a78e0424f8724f95169331a29ad0c55300b4dbd /planetwars-server/src/db/matches.rs
parent3c2f4977e478dc7c6b243cab540ac2de4d0e6c84 (diff)
downloadplanetwars.dev-3113f762d83fab020e63d008d1a6cbd15b441362.tar.xz
planetwars.dev-3113f762d83fab020e63d008d1a6cbd15b441362.zip
list matches for a specific bot
Diffstat (limited to 'planetwars-server/src/db/matches.rs')
-rw-r--r--planetwars-server/src/db/matches.rs30
1 files changed, 30 insertions, 0 deletions
diff --git a/planetwars-server/src/db/matches.rs b/planetwars-server/src/db/matches.rs
index c884a63..b806dd3 100644
--- a/planetwars-server/src/db/matches.rs
+++ b/planetwars-server/src/db/matches.rs
@@ -142,6 +142,36 @@ pub fn list_public_matches(amount: i64, conn: &PgConnection) -> QueryResult<Vec<
})
}
+pub fn list_bot_matches(
+ bot_id: i32,
+ amount: i64,
+ conn: &PgConnection,
+) -> QueryResult<Vec<FullMatchData>> {
+ conn.transaction(|| {
+ let matches = matches::table
+ .filter(matches::is_public.eq(true))
+ .order_by(matches::created_at.desc())
+ .inner_join(match_players::table)
+ .inner_join(
+ bot_versions::table
+ .on(match_players::bot_version_id.eq(bot_versions::id.nullable())),
+ )
+ .filter(bot_versions::bot_id.eq(bot_id))
+ .limit(amount)
+ .select((
+ matches::id,
+ matches::state,
+ matches::log_path,
+ matches::created_at,
+ matches::winner,
+ matches::is_public,
+ ))
+ .get_results::<MatchBase>(conn)?;
+
+ fetch_full_match_data(matches, conn)
+ })
+}
+
// TODO: maybe unify this with matchdata?
pub struct FullMatchData {
pub base: MatchBase,