diff options
Diffstat (limited to 'planetwars-server/src/routes')
-rw-r--r-- | planetwars-server/src/routes/bots.rs | 3 | ||||
-rw-r--r-- | planetwars-server/src/routes/demo.rs | 10 |
2 files changed, 6 insertions, 7 deletions
diff --git a/planetwars-server/src/routes/bots.rs b/planetwars-server/src/routes/bots.rs index 9ddb109..fc180d8 100644 --- a/planetwars-server/src/routes/bots.rs +++ b/planetwars-server/src/routes/bots.rs @@ -167,8 +167,9 @@ pub async fn get_my_bots( .map_err(|_| StatusCode::INTERNAL_SERVER_ERROR) } +/// List all active bots pub async fn list_bots(conn: DatabaseConnection) -> Result<Json<Vec<Bot>>, StatusCode> { - bots::find_all_bots(&conn) + bots::find_active_bots(&conn) .map(Json) .map_err(|_| StatusCode::INTERNAL_SERVER_ERROR) } diff --git a/planetwars-server/src/routes/demo.rs b/planetwars-server/src/routes/demo.rs index 69838f3..dad9453 100644 --- a/planetwars-server/src/routes/demo.rs +++ b/planetwars-server/src/routes/demo.rs @@ -28,8 +28,7 @@ pub struct SubmitBotResponse { pub match_data: ApiMatch, } -/// submit python code for a bot, which will face off -/// with a demo bot. Return a played match. +/// Submit bot code and opponent name to play a match pub async fn submit_bot( Json(params): Json<SubmitBotParams>, Extension(pool): Extension<ConnectionPool>, @@ -41,10 +40,9 @@ pub async fn submit_bot( .opponent_name .unwrap_or_else(|| DEFAULT_OPPONENT_NAME.to_string()); - let opponent_bot = - db::bots::find_bot_by_name(&opponent_name, &conn).map_err(|_| StatusCode::BAD_REQUEST)?; - let opponent_bot_version = db::bots::active_bot_version(opponent_bot.id, &conn) - .map_err(|_| StatusCode::BAD_REQUEST)?; + let (opponent_bot, opponent_bot_version) = + db::bots::find_bot_with_version_by_name(&opponent_name, &conn) + .map_err(|_| StatusCode::BAD_REQUEST)?; let player_bot_version = save_code_string(¶ms.code, None, &conn, &config) // TODO: can we recover from this? |