diff --git a/web/src/api.rs b/web/src/api.rs index dc86785..ff6bd79 100644 --- a/web/src/api.rs +++ b/web/src/api.rs @@ -14,6 +14,7 @@ use std::collections::{BTreeMap, BTreeSet}; use base64; +use chrono::NaiveDate; use reqwasm; use serde_json::{from_str, to_string}; use sycamore::prelude::*; @@ -585,6 +586,46 @@ impl HttpStore { } } + pub async fn fetch_plan_dates(&self) -> Result>, Error> { + let mut path = self.v2_path(); + path.push_str("/plan"); + path.push_str("/all"); + let resp = reqwasm::http::Request::get(&path).send().await?; + if resp.status() != 200 { + Err(format!("Status: {}", resp.status()).into()) + } else { + debug!("We got a valid response back"); + let plan = resp + .json::>>() + .await + .map_err(|e| format!("{}", e))? + .as_success(); + Ok(plan) + } + } + + pub async fn fetch_plan_for_date( + &self, + date: NaiveDate, + ) -> Result>, Error> { + let mut path = self.v2_path(); + path.push_str("/plan"); + path.push_str("/at"); + path.push_str(&format!("/{}", date)); + let resp = reqwasm::http::Request::get(&path).send().await?; + if resp.status() != 200 { + Err(format!("Status: {}", resp.status()).into()) + } else { + debug!("We got a valid response back"); + let plan = resp + .json::() + .await + .map_err(|e| format!("{}", e))? + .as_success(); + Ok(plan) + } + } + pub async fn fetch_plan(&self) -> Result>, Error> { let mut path = self.v2_path(); path.push_str("/plan");