diff options
Diffstat (limited to 'planetwars-server/src/db')
-rw-r--r-- | planetwars-server/src/db/matches.rs | 21 | ||||
-rw-r--r-- | planetwars-server/src/db/users.rs | 2 |
2 files changed, 13 insertions, 10 deletions
diff --git a/planetwars-server/src/db/matches.rs b/planetwars-server/src/db/matches.rs index 36c2200..efaa1eb 100644 --- a/planetwars-server/src/db/matches.rs +++ b/planetwars-server/src/db/matches.rs @@ -46,16 +46,16 @@ pub struct MatchPlayerData { } pub fn create_match( - match_data: &NewMatch, - match_players: &[MatchPlayerData], + new_match_base: &NewMatch, + new_match_players: &[MatchPlayerData], conn: &PgConnection, -) -> QueryResult<i32> { +) -> QueryResult<MatchData> { conn.transaction(|| { let match_base = diesel::insert_into(matches::table) - .values(match_data) + .values(new_match_base) .get_result::<MatchBase>(conn)?; - let match_players = match_players + let new_match_players = new_match_players .iter() .enumerate() .map(|(num, player_data)| NewMatchPlayer { @@ -65,11 +65,14 @@ pub fn create_match( }) .collect::<Vec<_>>(); - diesel::insert_into(match_players::table) - .values(&match_players) - .execute(conn)?; + let match_players = diesel::insert_into(match_players::table) + .values(&new_match_players) + .get_results::<MatchPlayer>(conn)?; - Ok(match_base.id) + Ok(MatchData { + base: match_base, + match_players, + }) }) } diff --git a/planetwars-server/src/db/users.rs b/planetwars-server/src/db/users.rs index 663f173..a97ade5 100644 --- a/planetwars-server/src/db/users.rs +++ b/planetwars-server/src/db/users.rs @@ -2,7 +2,7 @@ use crate::schema::users; use argon2; use diesel::{prelude::*, PgConnection}; use rand::Rng; -use serde::{Deserialize, Serialize}; +use serde::Deserialize; #[derive(Debug, Deserialize)] pub struct Credentials<'a> { |