From 3113f762d83fab020e63d008d1a6cbd15b441362 Mon Sep 17 00:00:00 2001 From: Ilion Beyst Date: Thu, 4 Aug 2022 21:48:25 +0200 Subject: list matches for a specific bot --- planetwars-server/src/db/matches.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'planetwars-server/src/db/matches.rs') 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 QueryResult> { + 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::(conn)?; + + fetch_full_match_data(matches, conn) + }) +} + // TODO: maybe unify this with matchdata? pub struct FullMatchData { pub base: MatchBase, -- cgit v1.2.3