From 6c9651194fda7a9167157e835fbe9fd691e9a1a9 Mon Sep 17 00:00:00 2001 From: Kjetil Orbekk Date: Fri, 23 Dec 2022 11:29:37 -0500 Subject: Replace table with a struct component This makes async & state handling much easier --- webapp/src/services.rs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 webapp/src/services.rs (limited to 'webapp/src/services.rs') 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 { + 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 +} -- cgit v1.2.3