diff options
author | Ilion Beyst <ilion.beyst@gmail.com> | 2022-08-28 17:15:56 +0200 |
---|---|---|
committer | Ilion Beyst <ilion.beyst@gmail.com> | 2022-08-28 17:15:56 +0200 |
commit | c6c484daf3b083af70b50451db9409a7dec0bf24 (patch) | |
tree | 2350fd40e9a7b316bf7535f87304848106f88ef3 /planetwars-server/src | |
parent | 2aab23c40f663a28fb361d6a7976493cb7bb5ea8 (diff) | |
download | planetwars.dev-c6c484daf3b083af70b50451db9409a7dec0bf24.tar.xz planetwars.dev-c6c484daf3b083af70b50451db9409a7dec0bf24.zip |
add missing maps routes
Diffstat (limited to 'planetwars-server/src')
-rw-r--r-- | planetwars-server/src/routes/maps.rs | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/planetwars-server/src/routes/maps.rs b/planetwars-server/src/routes/maps.rs new file mode 100644 index 0000000..689b11e --- /dev/null +++ b/planetwars-server/src/routes/maps.rs @@ -0,0 +1,19 @@ +use crate::{db, DatabaseConnection}; +use axum::Json; +use hyper::StatusCode; +use serde::{Deserialize, Serialize}; + +#[derive(Serialize, Deserialize)] +pub struct ApiMap { + pub name: String, +} + +pub async fn list_maps(conn: DatabaseConnection) -> Result<Json<Vec<ApiMap>>, StatusCode> { + let maps = db::maps::list_maps(&conn).map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?; + + let api_maps = maps + .into_iter() + .map(|map| ApiMap { name: map.name }) + .collect(); + Ok(Json(api_maps)) +} |