diff options
author | Kjetil Orbekk <kj@orbekk.com> | 2022-12-23 11:29:37 -0500 |
---|---|---|
committer | Kjetil Orbekk <kj@orbekk.com> | 2022-12-23 11:30:01 -0500 |
commit | 6c9651194fda7a9167157e835fbe9fd691e9a1a9 (patch) | |
tree | 4e24f243bde8923f15b125db863ba58732617251 /webapp/src/services.rs | |
parent | 868703627bfd27925a53fcfbdd3dbeef831660c8 (diff) |
Replace table with a struct component
This makes async & state handling much easier
Diffstat (limited to 'webapp/src/services.rs')
-rw-r--r-- | webapp/src/services.rs | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/webapp/src/services.rs b/webapp/src/services.rs new file mode 100644 index 0000000..212363f --- /dev/null +++ b/webapp/src/services.rs @@ -0,0 +1,36 @@ +use anyhow::Context; +use gloo_net::http::Request; +use protocol::{bridge_engine::{GameStatePlayerView, Bid}, Table, card::Card}; + +use crate::utils::ok_json; + +pub async fn get_table_player_view( + table: Table, +) -> Result<GameStatePlayerView, anyhow::Error> { + let response = Request::get(&format!("/api/table/{}", table.id)) + .send() + .await + .context("fetching table data")?; + let table = ok_json(response).await?; + Ok(table) +} + +pub async fn bid(table: Table, bid: Bid) -> Result<(), anyhow::Error> { + let response = + Request::post(&format!("/api/table/{}/bid", table.id)) + .json(&bid)? + .send() + .await + .context("submitting bid")?; + ok_json(response).await +} + +pub async fn play(table: Table, card: Card) -> Result<(), anyhow::Error> { + let response = + Request::post(&format!("/api/table/{}/play", table.id)) + .json(&card)? + .send() + .await + .context("submitting play")?; + ok_json(response).await +} |