aboutsummaryrefslogtreecommitdiff
path: root/planetwars-server/src/routes/maps.rs
blob: 188089f2d0a99484dc8c0e611ff3ec52322f9740 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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(mut conn: DatabaseConnection) -> Result<Json<Vec<ApiMap>>, StatusCode> {
    let maps = db::maps::list_maps(&mut conn).map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;

    let api_maps = maps
        .into_iter()
        .map(|map| ApiMap { name: map.name })
        .collect();
    Ok(Json(api_maps))
}