aboutsummaryrefslogtreecommitdiff
path: root/planetwars-server
diff options
context:
space:
mode:
Diffstat (limited to 'planetwars-server')
-rw-r--r--planetwars-server/migrations/2021-12-18-130837_bots/up.sql2
-rw-r--r--planetwars-server/src/db/bots.rs4
-rw-r--r--planetwars-server/src/routes/bots.rs4
-rw-r--r--planetwars-server/src/schema.rs2
4 files changed, 6 insertions, 6 deletions
diff --git a/planetwars-server/migrations/2021-12-18-130837_bots/up.sql b/planetwars-server/migrations/2021-12-18-130837_bots/up.sql
index 27f3582..22e250b 100644
--- a/planetwars-server/migrations/2021-12-18-130837_bots/up.sql
+++ b/planetwars-server/migrations/2021-12-18-130837_bots/up.sql
@@ -1,6 +1,6 @@
CREATE TABLE bots (
id serial PRIMARY KEY,
- owner_id integer REFERENCES users(id) NOT NULL,
+ owner_id integer REFERENCES users(id),
name text NOT NULL
);
diff --git a/planetwars-server/src/db/bots.rs b/planetwars-server/src/db/bots.rs
index 970dcf9..f7d8373 100644
--- a/planetwars-server/src/db/bots.rs
+++ b/planetwars-server/src/db/bots.rs
@@ -7,14 +7,14 @@ use chrono;
#[derive(Insertable)]
#[table_name = "bots"]
pub struct NewBot<'a> {
- pub owner_id: i32,
+ pub owner_id: Option<i32>,
pub name: &'a str,
}
#[derive(Queryable, Debug, PartialEq, Serialize, Deserialize)]
pub struct Bot {
pub id: i32,
- pub owner_id: i32,
+ pub owner_id: Option<i32>,
pub name: String,
}
diff --git a/planetwars-server/src/routes/bots.rs b/planetwars-server/src/routes/bots.rs
index 5f5d8f5..0edfaa9 100644
--- a/planetwars-server/src/routes/bots.rs
+++ b/planetwars-server/src/routes/bots.rs
@@ -24,7 +24,7 @@ pub async fn create_bot(
params: Json<BotParams>,
) -> (StatusCode, Json<Bot>) {
let bot_params = bots::NewBot {
- owner_id: user.id,
+ owner_id: Some(user.id),
name: &params.name,
};
let bot = bots::create_bot(&bot_params, &conn).unwrap();
@@ -71,7 +71,7 @@ pub async fn upload_code_multipart(
let bot = bots::find_bot(bot_id, &conn).map_err(|_| StatusCode::NOT_FOUND)?;
- if user.id != bot.owner_id {
+ if Some(user.id) != bot.owner_id {
return Err(StatusCode::FORBIDDEN);
}
diff --git a/planetwars-server/src/schema.rs b/planetwars-server/src/schema.rs
index 5e74e85..e67ef3a 100644
--- a/planetwars-server/src/schema.rs
+++ b/planetwars-server/src/schema.rs
@@ -7,7 +7,7 @@ table! {
bots (id) {
id -> Int4,
- owner_id -> Int4,
+ owner_id -> Nullable<Int4>,
name -> Text,
}
}