diff options
author | Ilion Beyst <ilion.beyst@gmail.com> | 2022-01-03 23:33:00 +0100 |
---|---|---|
committer | Ilion Beyst <ilion.beyst@gmail.com> | 2022-01-03 23:36:19 +0100 |
commit | 5b10d5e98e806ce867d27c4cc7b7f5651656744f (patch) | |
tree | 1397bc803f1b87e8811be05334a7aeb45032811b /planetwars-server/src | |
parent | 1cde40b45916d1f99a4cda7837b516cde761f127 (diff) | |
download | planetwars.dev-5b10d5e98e806ce867d27c4cc7b7f5651656744f.tar.xz planetwars.dev-5b10d5e98e806ce867d27c4cc7b7f5651656744f.zip |
add match_state to matches
Diffstat (limited to 'planetwars-server/src')
-rw-r--r-- | planetwars-server/src/db/matches.rs | 3 | ||||
-rw-r--r-- | planetwars-server/src/db_types.rs | 9 | ||||
-rw-r--r-- | planetwars-server/src/lib.rs | 1 | ||||
-rw-r--r-- | planetwars-server/src/routes/matches.rs | 9 | ||||
-rw-r--r-- | planetwars-server/src/schema.rs | 28 |
5 files changed, 47 insertions, 3 deletions
diff --git a/planetwars-server/src/db/matches.rs b/planetwars-server/src/db/matches.rs index 9bf00db..36c2200 100644 --- a/planetwars-server/src/db/matches.rs +++ b/planetwars-server/src/db/matches.rs @@ -1,3 +1,4 @@ +pub use crate::db_types::MatchState; use chrono::NaiveDateTime; use diesel::{BelongingToDsl, QueryDsl, RunQueryDsl}; use diesel::{Connection, GroupedBy, PgConnection, QueryResult}; @@ -7,6 +8,7 @@ use crate::schema::{match_players, matches}; #[derive(Insertable)] #[table_name = "matches"] pub struct NewMatch<'a> { + pub state: MatchState, pub log_path: &'a str, } @@ -25,6 +27,7 @@ pub struct NewMatchPlayer { #[table_name = "matches"] pub struct MatchBase { pub id: i32, + pub state: MatchState, pub log_path: String, pub created_at: NaiveDateTime, } diff --git a/planetwars-server/src/db_types.rs b/planetwars-server/src/db_types.rs new file mode 100644 index 0000000..d1225d7 --- /dev/null +++ b/planetwars-server/src/db_types.rs @@ -0,0 +1,9 @@ +use diesel_derive_enum::DbEnum; + +#[derive(DbEnum, Debug, Clone, Copy, PartialEq, Eq, Hash)] +#[DieselType = "Match_state"] + +pub enum MatchState { + Playing, + Finished, +} diff --git a/planetwars-server/src/lib.rs b/planetwars-server/src/lib.rs index 754d062..b5a204e 100644 --- a/planetwars-server/src/lib.rs +++ b/planetwars-server/src/lib.rs @@ -4,6 +4,7 @@ extern crate diesel; pub mod db; +pub mod db_types; pub mod routes; pub mod schema; diff --git a/planetwars-server/src/routes/matches.rs b/planetwars-server/src/routes/matches.rs index 4dfd44e..fed0f7b 100644 --- a/planetwars-server/src/routes/matches.rs +++ b/planetwars-server/src/routes/matches.rs @@ -1,4 +1,4 @@ -use std::{io::Read, path::PathBuf}; +use std::path::PathBuf; use axum::{ extract::{Extension, Path}, @@ -10,7 +10,11 @@ use rand::{distributions::Alphanumeric, Rng}; use serde::{Deserialize, Serialize}; use crate::{ - db::{bots, matches, users::User}, + db::{ + bots, + matches::{self, MatchState}, + users::User, + }, ConnectionPool, DatabaseConnection, BOTS_DIR, MAPS_DIR, MATCHES_DIR, }; @@ -81,6 +85,7 @@ async fn run_match_task( pool: ConnectionPool, ) { let match_data = matches::NewMatch { + state: MatchState::Finished, log_path: &log_file_name, }; diff --git a/planetwars-server/src/schema.rs b/planetwars-server/src/schema.rs index 413c4d1..7f60d64 100644 --- a/planetwars-server/src/schema.rs +++ b/planetwars-server/src/schema.rs @@ -1,4 +1,7 @@ table! { + use diesel::sql_types::*; + use crate::db_types::*; + bots (id) { id -> Int4, owner_id -> Int4, @@ -7,6 +10,9 @@ table! { } table! { + use diesel::sql_types::*; + use crate::db_types::*; + code_bundles (id) { id -> Int4, bot_id -> Int4, @@ -16,6 +22,9 @@ table! { } table! { + use diesel::sql_types::*; + use crate::db_types::*; + match_players (match_id, player_id) { match_id -> Int4, bot_id -> Int4, @@ -24,14 +33,21 @@ table! { } table! { + use diesel::sql_types::*; + use crate::db_types::*; + matches (id) { id -> Int4, + state -> Match_state, log_path -> Text, created_at -> Timestamp, } } table! { + use diesel::sql_types::*; + use crate::db_types::*; + sessions (id) { id -> Int4, user_id -> Int4, @@ -40,6 +56,9 @@ table! { } table! { + use diesel::sql_types::*; + use crate::db_types::*; + users (id) { id -> Int4, username -> Varchar, @@ -54,4 +73,11 @@ joinable!(match_players -> bots (bot_id)); joinable!(match_players -> matches (match_id)); joinable!(sessions -> users (user_id)); -allow_tables_to_appear_in_same_query!(bots, code_bundles, match_players, matches, sessions, users,); +allow_tables_to_appear_in_same_query!( + bots, + code_bundles, + match_players, + matches, + sessions, + users, +); |