diff options
author | Ilion Beyst <ilion.beyst@gmail.com> | 2022-10-13 22:22:45 +0200 |
---|---|---|
committer | Ilion Beyst <ilion.beyst@gmail.com> | 2022-10-13 22:22:45 +0200 |
commit | eb2cbb15fbea6dd6f800598329cd5cc892090d7b (patch) | |
tree | 7768204300a54b0bc4e71f3bb3f82519e8aa3196 /planetwars-server/src/db/matches.rs | |
parent | 2278ecd2584050c28e62f0f5fd8967b81d64cc5b (diff) | |
download | planetwars.dev-eb2cbb15fbea6dd6f800598329cd5cc892090d7b.tar.xz planetwars.dev-eb2cbb15fbea6dd6f800598329cd5cc892090d7b.zip |
save matchplayer had_errors in database
Diffstat (limited to 'planetwars-server/src/db/matches.rs')
-rw-r--r-- | planetwars-server/src/db/matches.rs | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/planetwars-server/src/db/matches.rs b/planetwars-server/src/db/matches.rs index d628b14..43e93a3 100644 --- a/planetwars-server/src/db/matches.rs +++ b/planetwars-server/src/db/matches.rs @@ -55,6 +55,7 @@ pub struct MatchPlayer { pub match_id: i32, pub player_id: i32, pub code_bundle_id: Option<i32>, + pub had_errors: Option<bool>, } pub struct MatchPlayerData { @@ -190,7 +191,7 @@ pub fn list_bot_matches( amount, }; - let matches = lbm.get_results::<MatchBase>(conn)?; + let matches = lbm.get_results(conn)?; fetch_full_match_data(matches, conn) } @@ -294,6 +295,24 @@ pub fn save_match_result(id: i32, result: MatchResult, conn: &mut PgConnection) Ok(()) } +pub fn set_player_had_errors( + match_id: i32, + player_id: i32, + had_errors: bool, + conn: &mut PgConnection, +) -> QueryResult<()> { + let num_modified = diesel::update(match_players::table) + .filter(match_players::match_id.eq(match_id)) + .filter(match_players::player_id.eq(player_id)) + .set(match_players::had_errors.eq(had_errors)) + .execute(conn)?; + if num_modified == 0 { + Err(diesel::result::Error::NotFound) + } else { + Ok(()) + } +} + #[derive(QueryableByName)] pub struct BotStatsRecord { #[diesel(sql_type = Text)] |