Started working on races...
This commit is contained in:
parent
9be403d4cc
commit
f25ff85276
|
@ -10,6 +10,6 @@ chrono = { version = "0.4.24", features = ["serde"] }
|
||||||
dotenvy = "0.15.7"
|
dotenvy = "0.15.7"
|
||||||
rocket = { version = "0.5.0-rc.2", features = ["json"] }
|
rocket = { version = "0.5.0-rc.2", features = ["json"] }
|
||||||
serde = "1.0.154"
|
serde = "1.0.154"
|
||||||
sqlx = { version = "0.6", features = [ "runtime-tokio-rustls", "postgres", "chrono" ] }
|
sqlx = { version = "0.6", features = [ "runtime-tokio-rustls", "postgres", "chrono", "uuid" ] }
|
||||||
#tokio = { version = "1.27.0", features = ["full"] }
|
|
||||||
tokio-test = "0.4.2"
|
tokio-test = "0.4.2"
|
||||||
|
uuid = "1.3.1"
|
|
@ -125,6 +125,122 @@ impl Map {
|
||||||
.fetch_one(&db.pool)
|
.fetch_one(&db.pool)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn get_maps_by_category(
|
||||||
|
db: &DatabaseHandler,
|
||||||
|
category: &str,
|
||||||
|
) -> Result<Vec<Map>, sqlx::Error> {
|
||||||
|
sqlx::query_as!(
|
||||||
|
Map,
|
||||||
|
"
|
||||||
|
SELECT record_maps.map, category, points, stars, mapper, release, width, height,
|
||||||
|
string_to_array(CONCAT_WS(',',
|
||||||
|
CASE WHEN DEATH = '1' THEN 'DEATH' END,
|
||||||
|
CASE WHEN THROUGH = '1' THEN 'THROUGH' END,
|
||||||
|
CASE WHEN JUMP = '1' THEN 'JUMP' END,
|
||||||
|
CASE WHEN DFREEZE = '1' THEN 'DFREEZE' END,
|
||||||
|
CASE WHEN EHOOK_START = '1' THEN 'EHOOK_START' END,
|
||||||
|
CASE WHEN HIT_END = '1' THEN 'HIT_END' END,
|
||||||
|
CASE WHEN SOLO_START = '1' THEN 'SOLO_START' END,
|
||||||
|
CASE WHEN TELE_GUN = '1' THEN 'TELE_GUN' END,
|
||||||
|
CASE WHEN TELE_GRENADE = '1' THEN 'TELE_GRENADE' END,
|
||||||
|
CASE WHEN TELE_LASER = '1' THEN 'TELE_LASER' END,
|
||||||
|
CASE WHEN NPC_START = '1' THEN 'NPC_START' END,
|
||||||
|
CASE WHEN SUPER_START = '1' THEN 'SUPER_START' END,
|
||||||
|
CASE WHEN JETPACK_START = '1' THEN 'JETPACK_START' END,
|
||||||
|
CASE WHEN WALLJUMP = '1' THEN 'WALLJUMP' END,
|
||||||
|
CASE WHEN NPH_START = '1' THEN 'NPH_START' END,
|
||||||
|
CASE WHEN WEAPON_SHOTGUN = '1' THEN 'WEAPON_SHOTGUN' END,
|
||||||
|
CASE WHEN WEAPON_GRENADE = '1' THEN 'WEAPON_GRENADE' END,
|
||||||
|
CASE WHEN POWERUP_NINJA = '1' THEN 'POWERUP_NINJA' END,
|
||||||
|
CASE WHEN WEAPON_RIFLE = '1' THEN 'WEAPON_RIFLE' END,
|
||||||
|
CASE WHEN LASER_STOP = '1' THEN 'LASER_STOP' END,
|
||||||
|
CASE WHEN CRAZY_SHOTGUN = '1' THEN 'CRAZY_SHOTGUN' END,
|
||||||
|
CASE WHEN DRAGGER = '1' THEN 'DRAGGER' END,
|
||||||
|
CASE WHEN DOOR = '1' THEN 'DOOR' END,
|
||||||
|
CASE WHEN SWITCH_TIMED = '1' THEN 'SWITCH_TIMED' END,
|
||||||
|
CASE WHEN SWITCH = '1' THEN 'SWITCH' END,
|
||||||
|
CASE WHEN STOP = '1' THEN 'STOP' END,
|
||||||
|
CASE WHEN THROUGH_ALL = '1' THEN 'THROUGH_ALL' END,
|
||||||
|
CASE WHEN TUNE = '1' THEN 'TUNE' END,
|
||||||
|
CASE WHEN OLDLASER = '1' THEN 'OLDLASER' END,
|
||||||
|
CASE WHEN TELEINEVIL = '1' THEN 'TELEINEVIL' END,
|
||||||
|
CASE WHEN TELEIN = '1' THEN 'TELEIN' END,
|
||||||
|
CASE WHEN TELECHECK = '1' THEN 'TELECHECK' END,
|
||||||
|
CASE WHEN TELEINWEAPON = '1' THEN 'TELEINWEAPON' END,
|
||||||
|
CASE WHEN TELEINHOOK = '1' THEN 'TELEINHOOK' END,
|
||||||
|
CASE WHEN CHECKPOINT_FIRST = '1' THEN 'CHECKPOINT_FIRST' END,
|
||||||
|
CASE WHEN BONUS = '1' THEN 'BONUS' END,
|
||||||
|
CASE WHEN BOOST = '1' THEN 'BOOST' END,
|
||||||
|
CASE WHEN PLASMAF = '1' THEN 'PLASMAF' END,
|
||||||
|
CASE WHEN PLASMAE = '1' THEN 'PLASMAE' END,
|
||||||
|
CASE WHEN PLASMAU = '1' THEN 'PLASMAU' END), ',') AS tiles
|
||||||
|
FROM record_maps JOIN record_mapinfo ON record_maps.map = record_mapinfo.map
|
||||||
|
WHERE category = $1;
|
||||||
|
",
|
||||||
|
category
|
||||||
|
)
|
||||||
|
.fetch_all(&db.pool)
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn get_maps_by_mapper(
|
||||||
|
db: &DatabaseHandler,
|
||||||
|
mapper: &str,
|
||||||
|
) -> Result<Vec<Map>, sqlx::Error> {
|
||||||
|
sqlx::query_as!(
|
||||||
|
Map,
|
||||||
|
"
|
||||||
|
SELECT record_maps.map, category, points, stars, mapper, release, width, height,
|
||||||
|
string_to_array(CONCAT_WS(',',
|
||||||
|
CASE WHEN DEATH = '1' THEN 'DEATH' END,
|
||||||
|
CASE WHEN THROUGH = '1' THEN 'THROUGH' END,
|
||||||
|
CASE WHEN JUMP = '1' THEN 'JUMP' END,
|
||||||
|
CASE WHEN DFREEZE = '1' THEN 'DFREEZE' END,
|
||||||
|
CASE WHEN EHOOK_START = '1' THEN 'EHOOK_START' END,
|
||||||
|
CASE WHEN HIT_END = '1' THEN 'HIT_END' END,
|
||||||
|
CASE WHEN SOLO_START = '1' THEN 'SOLO_START' END,
|
||||||
|
CASE WHEN TELE_GUN = '1' THEN 'TELE_GUN' END,
|
||||||
|
CASE WHEN TELE_GRENADE = '1' THEN 'TELE_GRENADE' END,
|
||||||
|
CASE WHEN TELE_LASER = '1' THEN 'TELE_LASER' END,
|
||||||
|
CASE WHEN NPC_START = '1' THEN 'NPC_START' END,
|
||||||
|
CASE WHEN SUPER_START = '1' THEN 'SUPER_START' END,
|
||||||
|
CASE WHEN JETPACK_START = '1' THEN 'JETPACK_START' END,
|
||||||
|
CASE WHEN WALLJUMP = '1' THEN 'WALLJUMP' END,
|
||||||
|
CASE WHEN NPH_START = '1' THEN 'NPH_START' END,
|
||||||
|
CASE WHEN WEAPON_SHOTGUN = '1' THEN 'WEAPON_SHOTGUN' END,
|
||||||
|
CASE WHEN WEAPON_GRENADE = '1' THEN 'WEAPON_GRENADE' END,
|
||||||
|
CASE WHEN POWERUP_NINJA = '1' THEN 'POWERUP_NINJA' END,
|
||||||
|
CASE WHEN WEAPON_RIFLE = '1' THEN 'WEAPON_RIFLE' END,
|
||||||
|
CASE WHEN LASER_STOP = '1' THEN 'LASER_STOP' END,
|
||||||
|
CASE WHEN CRAZY_SHOTGUN = '1' THEN 'CRAZY_SHOTGUN' END,
|
||||||
|
CASE WHEN DRAGGER = '1' THEN 'DRAGGER' END,
|
||||||
|
CASE WHEN DOOR = '1' THEN 'DOOR' END,
|
||||||
|
CASE WHEN SWITCH_TIMED = '1' THEN 'SWITCH_TIMED' END,
|
||||||
|
CASE WHEN SWITCH = '1' THEN 'SWITCH' END,
|
||||||
|
CASE WHEN STOP = '1' THEN 'STOP' END,
|
||||||
|
CASE WHEN THROUGH_ALL = '1' THEN 'THROUGH_ALL' END,
|
||||||
|
CASE WHEN TUNE = '1' THEN 'TUNE' END,
|
||||||
|
CASE WHEN OLDLASER = '1' THEN 'OLDLASER' END,
|
||||||
|
CASE WHEN TELEINEVIL = '1' THEN 'TELEINEVIL' END,
|
||||||
|
CASE WHEN TELEIN = '1' THEN 'TELEIN' END,
|
||||||
|
CASE WHEN TELECHECK = '1' THEN 'TELECHECK' END,
|
||||||
|
CASE WHEN TELEINWEAPON = '1' THEN 'TELEINWEAPON' END,
|
||||||
|
CASE WHEN TELEINHOOK = '1' THEN 'TELEINHOOK' END,
|
||||||
|
CASE WHEN CHECKPOINT_FIRST = '1' THEN 'CHECKPOINT_FIRST' END,
|
||||||
|
CASE WHEN BONUS = '1' THEN 'BONUS' END,
|
||||||
|
CASE WHEN BOOST = '1' THEN 'BOOST' END,
|
||||||
|
CASE WHEN PLASMAF = '1' THEN 'PLASMAF' END,
|
||||||
|
CASE WHEN PLASMAE = '1' THEN 'PLASMAE' END,
|
||||||
|
CASE WHEN PLASMAU = '1' THEN 'PLASMAU' END), ',') AS tiles
|
||||||
|
FROM record_maps JOIN record_mapinfo ON record_maps.map = record_mapinfo.map
|
||||||
|
WHERE mapper = $1;
|
||||||
|
",
|
||||||
|
mapper
|
||||||
|
)
|
||||||
|
.fetch_all(&db.pool)
|
||||||
|
.await
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
|
@ -1 +1,2 @@
|
||||||
pub mod map;
|
pub mod map;
|
||||||
|
pub mod race;
|
||||||
|
|
47
src/database/models/race.rs
Normal file
47
src/database/models/race.rs
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
use chrono::NaiveDateTime;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
use crate::database::DatabaseHandler;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, sqlx::FromRow, Serialize, Deserialize)]
|
||||||
|
pub struct Race {
|
||||||
|
name: Option<String>,
|
||||||
|
map: Option<String>,
|
||||||
|
time: Option<f64>,
|
||||||
|
timestamp: Option<NaiveDateTime>,
|
||||||
|
server: Option<String>,
|
||||||
|
checkpoints: Option<Vec<f64>>,
|
||||||
|
gameid: Option<String>,
|
||||||
|
ddnet7: Option<i16>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Race {
|
||||||
|
pub async fn get_races_by_player(
|
||||||
|
db: &DatabaseHandler,
|
||||||
|
player: &str,
|
||||||
|
) -> Result<Vec<Race>, sqlx::Error> {
|
||||||
|
sqlx::query_as!(
|
||||||
|
Race,
|
||||||
|
"
|
||||||
|
SELECT name,
|
||||||
|
map,
|
||||||
|
time,
|
||||||
|
timestamp,
|
||||||
|
server,
|
||||||
|
ARRAY[cp1, cp2, cp3, cp4, cp5,
|
||||||
|
cp6, cp7, cp8, cp9, cp10,
|
||||||
|
cp11, cp12, cp13, cp14, cp15,
|
||||||
|
cp16, cp17, cp18, cp19, cp20,
|
||||||
|
cp21, cp22, cp23, cp24, cp25
|
||||||
|
] AS checkpoints,
|
||||||
|
gameid,
|
||||||
|
ddnet7
|
||||||
|
FROM record_race WHERE name = $1
|
||||||
|
ORDER BY map, time
|
||||||
|
",
|
||||||
|
player
|
||||||
|
)
|
||||||
|
.fetch_all(&db.pool)
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user