Now can access races and teamraces.
This commit is contained in:
parent
5f6c3b6c52
commit
9ed1d728da
|
@ -1 +1,3 @@
|
|||
pub mod maps;
|
||||
pub mod races;
|
||||
pub mod teamraces;
|
||||
|
|
18
src/api/races.rs
Normal file
18
src/api/races.rs
Normal file
|
@ -0,0 +1,18 @@
|
|||
use rocket::{serde::json::Json, Route, State};
|
||||
|
||||
use crate::database::{models::race::Race, DatabaseHandler};
|
||||
|
||||
#[get("/player/<player>")]
|
||||
async fn get_races_by_player(
|
||||
db: &State<DatabaseHandler>,
|
||||
player: &str,
|
||||
) -> Result<Json<Vec<Race>>, String> {
|
||||
match Race::get_races_by_player(db, player).await {
|
||||
Ok(maps) => Ok(Json(maps)),
|
||||
Err(err) => Err(format!("Error: {}", err)),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_all_routes() -> Vec<Route> {
|
||||
routes![get_races_by_player]
|
||||
}
|
29
src/api/teamraces.rs
Normal file
29
src/api/teamraces.rs
Normal file
|
@ -0,0 +1,29 @@
|
|||
use rocket::{serde::json::Json, Route, State};
|
||||
|
||||
use crate::database::{models::teamrace::Teamrace, DatabaseHandler};
|
||||
|
||||
#[get("/player/<player>")]
|
||||
async fn get_teamrace_by_player(
|
||||
db: &State<DatabaseHandler>,
|
||||
player: &str,
|
||||
) -> Result<Json<Vec<Teamrace>>, String> {
|
||||
match Teamrace::get_teamrace_by_player(db, player).await {
|
||||
Ok(maps) => Ok(Json(maps)),
|
||||
Err(err) => Err(format!("Error: {}", err)),
|
||||
}
|
||||
}
|
||||
|
||||
#[get("/map/<map>")]
|
||||
async fn get_teamrace_by_map(
|
||||
db: &State<DatabaseHandler>,
|
||||
map: &str,
|
||||
) -> Result<Json<Vec<Teamrace>>, String> {
|
||||
match Teamrace::get_teamrace_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_teamrace_by_player, get_teamrace_by_map]
|
||||
}
|
|
@ -19,6 +19,8 @@ async fn main() {
|
|||
match rocket::build()
|
||||
.manage(db)
|
||||
.mount("/api/v1/maps", api::maps::get_all_routes())
|
||||
.mount("/api/v1/races", api::races::get_all_routes())
|
||||
.mount("/api/v1/teamraces", api::teamraces::get_all_routes())
|
||||
.launch()
|
||||
.await
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue
Block a user