diff options
author | Kjetil Orbekk <kj@orbekk.com> | 2022-12-18 15:33:02 -0500 |
---|---|---|
committer | Kjetil Orbekk <kj@orbekk.com> | 2022-12-18 15:33:02 -0500 |
commit | 27f74d8c366be675e7ab64ca746496a66b3cf024 (patch) | |
tree | 7bee8fee0b8753d1c3974e33bcb155b509bae100 /server | |
parent | 4512c5ead9406206de32e37490b7a4ac792d93bf (diff) |
Add bidding from webapp
Diffstat (limited to 'server')
-rw-r--r-- | server/Cargo.toml | 1 | ||||
-rw-r--r-- | server/src/main.rs | 2 | ||||
-rw-r--r-- | server/src/play.rs | 15 |
3 files changed, 13 insertions, 5 deletions
diff --git a/server/Cargo.toml b/server/Cargo.toml index ca3475d..9d5f1a8 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -6,6 +6,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +# TODO Upgrade to 0.6: https://github.com/tokio-rs/axum/blob/main/axum/CHANGELOG.md axum = "0.5" dotenv = "0.15.0" serde = { version = "1.0.145", features = ["derive"] } diff --git a/server/src/main.rs b/server/src/main.rs index a8429ec..5b81fc0 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -172,7 +172,7 @@ async fn post_bid( ) -> Result<Json<()>, BridgeError> { info!("Getting table state for {id:}"); let jnl = DbJournal::new(extension.db.clone(), id); - let mut table = play::Table::new_or_replay(jnl).await?; + let mut table = play::Table::replay(jnl).await?; if !table.game().is_bidding() { return Err(BridgeError::InvalidRequest( "Posting a bid requires that the game is in the bidding phase" diff --git a/server/src/play.rs b/server/src/play.rs index e78a19e..79d241c 100644 --- a/server/src/play.rs +++ b/server/src/play.rs @@ -4,6 +4,7 @@ use rand::random; use serde::{Deserialize, Serialize}; use serde_json::json; use sqlx::{query, PgPool}; +use tracing::info; use uuid::Uuid; use crate::error::BridgeError; @@ -56,9 +57,9 @@ impl Journal for DbJournal { } async fn replay(&mut self, seq: i64) -> Result<Vec<serde_json::Value>, BridgeError> { - let results = query!( + let rows =query!( r#" - select payload from object_journal + select seq, payload from object_journal where id = $1 and seq >= $2 order by seq "#, @@ -66,8 +67,13 @@ impl Journal for DbJournal { seq ) .fetch_all(&self.db) - .await?; - Ok(results.into_iter().map(|v| v.payload).collect()) + .await?; + let mut payloads = vec!(); + for v in rows { + payloads.push(v.payload); + self.seq = v.seq; + } + Ok(payloads) } fn next(&self) -> i64 { @@ -145,6 +151,7 @@ pub async fn advance_play<J: Journal>(table: &mut Table<J>) -> Result<(), Bridge let current_player = match table.game().current_player() { Some(player) => player, None => { + info!("Could not make play. Game: {:#?}", table.game()); return Err(BridgeError::InvalidRequest(format!("No play to make for game"))); }, }; |