Added way to get races by map.
This commit is contained in:
parent
9ed1d728da
commit
71ed4d8b70
|
@ -13,6 +13,17 @@ async fn get_races_by_player(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_all_routes() -> Vec<Route> {
|
#[get("/map/<map>")]
|
||||||
routes![get_races_by_player]
|
async fn get_races_by_map(
|
||||||
|
db: &State<DatabaseHandler>,
|
||||||
|
map: &str,
|
||||||
|
) -> Result<Json<Vec<Race>>, String> {
|
||||||
|
match Race::get_races_by_map(db, map).await {
|
||||||
|
Ok(maps) => Ok(Json(maps)),
|
||||||
|
Err(err) => Err(format!("Error: {}", err)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_all_routes() -> Vec<Route> {
|
||||||
|
routes![get_races_by_player, get_races_by_map]
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,4 +44,33 @@ impl Race {
|
||||||
.fetch_all(&db.pool)
|
.fetch_all(&db.pool)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn get_races_by_map(
|
||||||
|
db: &DatabaseHandler,
|
||||||
|
map: &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 map = $1
|
||||||
|
ORDER BY map, time
|
||||||
|
",
|
||||||
|
map
|
||||||
|
)
|
||||||
|
.fetch_all(&db.pool)
|
||||||
|
.await
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user