diff options
Diffstat (limited to 'server/src')
-rw-r--r-- | server/src/main.rs | 35 |
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( |