diff options
author | Kjetil Orbekk <kj@orbekk.com> | 2022-12-22 11:36:48 -0500 |
---|---|---|
committer | Kjetil Orbekk <kj@orbekk.com> | 2022-12-22 11:36:48 -0500 |
commit | c2145b91775be375779884a2a97365396923aba1 (patch) | |
tree | e8d1c52b98e8d2fcf1fda741bef8bc85ddeaa6f9 /server/src/main.rs | |
parent | 0ba28546b94a794d56c56bba35f035200fd0a434 (diff) |
Add typed journals
Diffstat (limited to 'server/src/main.rs')
-rw-r--r-- | server/src/main.rs | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/server/src/main.rs b/server/src/main.rs index 5b81fc0..35019c5 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -153,11 +153,20 @@ async fn get_table_view( let jnl = DbJournal::new(extension.db.clone(), id); let mut table = play::Table::new_or_replay(jnl).await?; info!("Advancing play"); - while table.game().current_player() != Some(player_position) { + while table + .game() + .ok_or(BridgeError::InvalidRequest( + "game not in progress".to_string(), + ))? + .current_player() + != player_position + { advance_play(&mut table).await?; } let response = Json(GameStatePlayerView::from_game_state( - table.game(), + table.game().ok_or(BridgeError::InvalidRequest( + "game not in progress".to_string(), + ))?, player_position, )); info!("Response: {response:#?}"); @@ -173,14 +182,27 @@ async fn post_bid( info!("Getting table state for {id:}"); let jnl = DbJournal::new(extension.db.clone(), id); let mut table = play::Table::replay(jnl).await?; - if !table.game().is_bidding() { + if !table + .game() + .ok_or(BridgeError::InvalidRequest( + "game not in progress".to_string(), + ))? + .is_bidding() + { return Err(BridgeError::InvalidRequest( "Posting a bid requires that the game is in the bidding phase" .to_string(), )); } let player_position = Player::South; - if table.game().current_player() != Some(player_position) { + if table + .game() + .ok_or(BridgeError::InvalidRequest( + "game not in progress".to_string(), + ))? + .current_player() + != player_position + { return Err(BridgeError::InvalidRequest(format!( "It is not {player_position:?} to play" ))); |