From 69331eb08a6199bfa8378e08cf378803b076eaae Mon Sep 17 00:00:00 2001 From: Ilion Beyst Date: Sun, 2 Jan 2022 17:56:52 +0100 Subject: serve match logs --- planetwars-server/src/db/matches.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'planetwars-server/src/db') diff --git a/planetwars-server/src/db/matches.rs b/planetwars-server/src/db/matches.rs index 85f0631..9bf00db 100644 --- a/planetwars-server/src/db/matches.rs +++ b/planetwars-server/src/db/matches.rs @@ -1,5 +1,5 @@ use chrono::NaiveDateTime; -use diesel::{BelongingToDsl, RunQueryDsl}; +use diesel::{BelongingToDsl, QueryDsl, RunQueryDsl}; use diesel::{Connection, GroupedBy, PgConnection, QueryResult}; use crate::schema::{match_players, matches}; @@ -95,3 +95,22 @@ pub fn list_matches(conn: &PgConnection) -> QueryResult> { Ok(res) }) } + +pub fn find_match(id: i32, conn: &PgConnection) -> QueryResult { + conn.transaction(|| { + let match_base = matches::table.find(id).get_result::(conn)?; + + let match_players = MatchPlayer::belonging_to(&match_base).load::(conn)?; + + let res = MatchData { + base: match_base, + match_players, + }; + + Ok(res) + }) +} + +pub fn find_mach_base(id: i32, conn: &PgConnection) -> QueryResult { + matches::table.find(id).get_result::(conn) +} -- cgit v1.2.3