diff options
author | Ilion Beyst <ilion.beyst@gmail.com> | 2021-12-31 11:24:25 +0100 |
---|---|---|
committer | Ilion Beyst <ilion.beyst@gmail.com> | 2021-12-31 11:24:25 +0100 |
commit | 3e902bb56e9626c8296e9836aa9ae19d82d48394 (patch) | |
tree | 3b6b11fdf68c8d41f2b2bceebe1c2469ebc00cb6 /planetwars-server/src/routes | |
parent | 0f27ca80fbdb3366e047def628123d3cc8ca051c (diff) | |
download | planetwars.dev-3e902bb56e9626c8296e9836aa9ae19d82d48394.tar.xz planetwars.dev-3e902bb56e9626c8296e9836aa9ae19d82d48394.zip |
list uploaded code bundles on bot page
Diffstat (limited to 'planetwars-server/src/routes')
-rw-r--r-- | planetwars-server/src/routes/bots.rs | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/planetwars-server/src/routes/bots.rs b/planetwars-server/src/routes/bots.rs index 83127cd..f722e52 100644 --- a/planetwars-server/src/routes/bots.rs +++ b/planetwars-server/src/routes/bots.rs @@ -5,6 +5,7 @@ use axum::Json; use rand::distributions::Alphanumeric; use rand::Rng; use serde::{Deserialize, Serialize}; +use serde_json::{json, value::Value as JsonValue}; use std::io::Cursor; use std::path::{self, PathBuf}; @@ -35,10 +36,17 @@ pub async fn create_bot( } // TODO: handle errors -pub async fn get_bot(conn: DatabaseConnection, Path(bot_id): Path<i32>) -> impl IntoResponse { - bots::find_bot(bot_id, &conn) - .map(Json) - .map_err(|_| StatusCode::NOT_FOUND) +pub async fn get_bot( + conn: DatabaseConnection, + Path(bot_id): Path<i32>, +) -> Result<Json<JsonValue>, StatusCode> { + let bot = bots::find_bot(bot_id, &conn).map_err(|_| StatusCode::NOT_FOUND)?; + let bundles = bots::find_bot_code_bundles(bot.id, &conn) + .map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?; + Ok(Json(json!({ + "bot": bot, + "bundles": bundles, + }))) } pub async fn get_my_bots( |