Can now get maps by mapper or category.

This commit is contained in:
BurnyLlama 2023-04-15 21:35:02 +02:00
parent c277eb5ebd
commit c3fa0f0202

View File

@ -10,6 +10,28 @@ async fn get_all_maps(db: &State<DatabaseHandler>) -> Result<Json<Vec<Map>>, Str
} }
} }
pub fn get_all_routes() -> Vec<Route> { #[get("/category/<category>")]
routes![get_all_maps] async fn get_maps_by_category(
db: &State<DatabaseHandler>,
category: &str,
) -> Result<Json<Vec<Map>>, String> {
match Map::get_maps_by_category(db, category).await {
Ok(maps) => Ok(Json(maps)),
Err(err) => Err(format!("Error: {}", err)),
}
}
#[get("/mapper/<mapper>")]
async fn get_maps_by_mapper(
db: &State<DatabaseHandler>,
mapper: &str,
) -> Result<Json<Vec<Map>>, String> {
match Map::get_maps_by_category(db, mapper).await {
Ok(maps) => Ok(Json(maps)),
Err(err) => Err(format!("Error: {}", err)),
}
}
pub fn get_all_routes() -> Vec<Route> {
routes![get_all_maps, get_maps_by_category, get_maps_by_mapper]
} }