summaryrefslogtreecommitdiff
path: root/server/src
diff options
context:
space:
mode:
authorKjetil Orbekk <kj@orbekk.com>2022-10-15 09:34:44 -0400
committerKjetil Orbekk <kj@orbekk.com>2022-10-15 09:34:44 -0400
commit2d9d37bd5e4770a05cae780f2113266f3fdd0915 (patch)
tree2348c12d2be7590c5fe4a64cf759f749c02413a7 /server/src
parent58f91c62065d9a7e37c953503100b87b506297e7 (diff)
Add table creation
Diffstat (limited to 'server/src')
-rw-r--r--server/src/main.rs35
1 files changed, 33 insertions, 2 deletions
diff --git a/server/src/main.rs b/server/src/main.rs
index 6896818..eaf1379 100644
--- a/server/src/main.rs
+++ b/server/src/main.rs
@@ -1,4 +1,5 @@
use std::{collections::HashMap, env, str::FromStr, sync::Arc};
+use uuid::Uuid;
use auth::AuthenticatedSession;
use axum::{
@@ -72,8 +73,38 @@ async fn main() {
.unwrap();
}
-async fn create_table(session: AuthenticatedSession) -> Result<(), BridgeError> {
- todo!()
+async fn create_table(
+ session: AuthenticatedSession,
+ extension: ContextExtension,
+) -> Result<Json<Uuid>, BridgeError> {
+ let txn = extension.db.begin().await?;
+ let table_id = sqlx::query!(
+ r#"
+ insert into active_tables (id)
+ values ($1)
+ returning id
+ "#,
+ Uuid::new_v4()
+ )
+ .fetch_one(&extension.db)
+ .await?
+ .id;
+
+ sqlx::query!(
+ r#"
+ insert into table_players (active_tables_id,
+ player_id,
+ position)
+ values ($1, $2, 'south')
+ "#,
+ table_id,
+ session.player_id
+ )
+ .execute(&extension.db)
+ .await?;
+
+ txn.commit().await?;
+ Ok(Json(table_id))
}
async fn user_info(