aboutsummaryrefslogtreecommitdiff
path: root/planetwars-server/src/routes
diff options
context:
space:
mode:
Diffstat (limited to 'planetwars-server/src/routes')
-rw-r--r--planetwars-server/src/routes/bots.rs9
-rw-r--r--planetwars-server/src/routes/users.rs2
2 files changed, 7 insertions, 4 deletions
diff --git a/planetwars-server/src/routes/bots.rs b/planetwars-server/src/routes/bots.rs
index fc180d8..896359c 100644
--- a/planetwars-server/src/routes/bots.rs
+++ b/planetwars-server/src/routes/bots.rs
@@ -12,6 +12,7 @@ use std::path::PathBuf;
use std::sync::Arc;
use thiserror;
+use crate::db;
use crate::db::bots::{self, BotVersion};
use crate::db::ratings::{self, RankedBot};
use crate::db::users::User;
@@ -158,11 +159,13 @@ pub async fn get_bot(
})))
}
-pub async fn get_my_bots(
+pub async fn get_user_bots(
conn: DatabaseConnection,
- user: User,
+ Path(user_name): Path<String>,
) -> Result<Json<Vec<Bot>>, StatusCode> {
- bots::find_bots_by_owner(user.id, &conn)
+ let user =
+ db::users::find_user_by_name(&user_name, &conn).map_err(|_| StatusCode::NOT_FOUND)?;
+ db::bots::find_bots_by_owner(user.id, &conn)
.map(Json)
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)
}
diff --git a/planetwars-server/src/routes/users.rs b/planetwars-server/src/routes/users.rs
index 1989904..faad1d1 100644
--- a/planetwars-server/src/routes/users.rs
+++ b/planetwars-server/src/routes/users.rs
@@ -89,7 +89,7 @@ impl RegistrationParams {
errors.push("password must be at least 8 characters".to_string());
}
- if users::find_user(&self.username, &conn).is_ok() {
+ if users::find_user_by_name(&self.username, &conn).is_ok() {
errors.push("username is already taken".to_string());
}