API naming consistency get_ -> fetch_

This commit is contained in:
Jeremy Wall 2023-01-05 11:45:58 -05:00
parent 19c75930cc
commit 30293878fc
5 changed files with 14 additions and 8 deletions

View File

@ -372,7 +372,7 @@ impl HttpStore {
} }
#[instrument] #[instrument]
pub async fn get_user_data(&self) -> Option<UserData> { pub async fn fetch_user_data(&self) -> Option<UserData> {
debug!("Retrieving User Account data"); debug!("Retrieving User Account data");
let mut path = self.v2_path(); let mut path = self.v2_path();
path.push_str("/account"); path.push_str("/account");
@ -393,7 +393,7 @@ impl HttpStore {
return None; return None;
} }
//#[instrument] //#[instrument]
pub async fn get_categories(&self) -> Result<Option<String>, Error> { pub async fn fetch_categories(&self) -> Result<Option<String>, Error> {
let mut path = self.v2_path(); let mut path = self.v2_path();
path.push_str("/categories"); path.push_str("/categories");
let resp = match reqwasm::http::Request::get(&path).send().await { let resp = match reqwasm::http::Request::get(&path).send().await {
@ -419,7 +419,7 @@ impl HttpStore {
} }
#[instrument] #[instrument]
pub async fn get_recipes(&self) -> Result<Option<Vec<RecipeEntry>>, Error> { pub async fn fetch_recipes(&self) -> Result<Option<Vec<RecipeEntry>>, Error> {
let mut path = self.v2_path(); let mut path = self.v2_path();
path.push_str("/recipes"); path.push_str("/recipes");
let resp = match reqwasm::http::Request::get(&path).send().await { let resp = match reqwasm::http::Request::get(&path).send().await {
@ -445,7 +445,7 @@ impl HttpStore {
} }
} }
pub async fn get_recipe_text<S: AsRef<str> + std::fmt::Display>( pub async fn fetch_recipe_text<S: AsRef<str> + std::fmt::Display>(
&self, &self,
id: S, id: S,
) -> Result<Option<RecipeEntry>, Error> { ) -> Result<Option<RecipeEntry>, Error> {
@ -559,7 +559,7 @@ impl HttpStore {
} }
} }
pub async fn get_plan(&self) -> Result<Option<Vec<(String, i32)>>, Error> { pub async fn fetch_plan(&self) -> Result<Option<Vec<(String, i32)>>, Error> {
let mut path = self.v2_path(); let mut path = self.v2_path();
path.push_str("/plan"); path.push_str("/plan");
let resp = reqwasm::http::Request::get(&path).send().await?; let resp = reqwasm::http::Request::get(&path).send().await?;
@ -576,6 +576,7 @@ impl HttpStore {
} }
} }
pub async fn fetch_inventory_data(
&self, &self,
) -> Result< ) -> Result<
( (

View File

@ -153,6 +153,7 @@ impl StateMachine {
) -> Result<(), crate::api::Error> { ) -> Result<(), crate::api::Error> {
let mut state = original.get().as_ref().clone(); let mut state = original.get().as_ref().clone();
info!("Synchronizing Recipes"); info!("Synchronizing Recipes");
let recipe_entries = &store.fetch_recipes().await?;
let (staples, recipes) = filter_recipes(&recipe_entries)?; let (staples, recipes) = filter_recipes(&recipe_entries)?;
if let Some(recipes) = recipes { if let Some(recipes) = recipes {
state.staples = staples; state.staples = staples;
@ -162,6 +163,7 @@ impl StateMachine {
local_store.set_all_recipes(recipe_entries); local_store.set_all_recipes(recipe_entries);
} }
let plan = store.fetch_plan().await?;
if let Some(plan) = plan { if let Some(plan) = plan {
// set the counts. // set the counts.
let mut plan_map = BTreeMap::new(); let mut plan_map = BTreeMap::new();
@ -184,6 +186,7 @@ impl StateMachine {
.collect::<Vec<(String, i32)>>(); .collect::<Vec<(String, i32)>>();
local_store.save_plan(&plan); local_store.save_plan(&plan);
info!("Checking for user account data"); info!("Checking for user account data");
if let Some(user_data) = store.fetch_user_data().await {
debug!("Successfully got account data from server"); debug!("Successfully got account data from server");
local_store.set_user_data(Some(&user_data)); local_store.set_user_data(Some(&user_data));
state.auth = Some(user_data); state.auth = Some(user_data);
@ -193,6 +196,7 @@ impl StateMachine {
state.auth = user_data; state.auth = user_data;
} }
info!("Synchronizing categories"); info!("Synchronizing categories");
match store.fetch_categories().await {
Ok(Some(categories_content)) => { Ok(Some(categories_content)) => {
debug!(categories=?categories_content); debug!(categories=?categories_content);
local_store.set_categories(Some(&categories_content)); local_store.set_categories(Some(&categories_content));
@ -207,6 +211,7 @@ impl StateMachine {
} }
} }
info!("Synchronizing inventory data"); info!("Synchronizing inventory data");
match store.fetch_inventory_data().await {
Ok((filtered_ingredients, modified_amts, extra_items)) => { Ok((filtered_ingredients, modified_amts, extra_items)) => {
local_store.set_inventory_data(( local_store.set_inventory_data((
&filtered_ingredients, &filtered_ingredients,

View File

@ -63,7 +63,7 @@ pub fn AddRecipe<'ctx, G: Html>(cx: Scope<'ctx>, sh: StateHandler<'ctx>) -> View
async move { async move {
let entry = entry.get_untracked(); let entry = entry.get_untracked();
// TODO(jwall): Better error reporting here. // TODO(jwall): Better error reporting here.
match store.get_recipe_text(entry.recipe_id()).await { match store.fetch_recipe_text(entry.recipe_id()).await {
Ok(Some(_)) => { Ok(Some(_)) => {
// TODO(jwall): We should tell the user that this id already exists // TODO(jwall): We should tell the user that this id already exists
info!(recipe_id = entry.recipe_id(), "Recipe already exists"); info!(recipe_id = entry.recipe_id(), "Recipe already exists");

View File

@ -51,7 +51,7 @@ pub fn Categories<'ctx, G: Html>(cx: Scope<'ctx>, sh: StateHandler<'ctx>) -> Vie
let store = crate::api::HttpStore::get_from_context(cx); let store = crate::api::HttpStore::get_from_context(cx);
async move { async move {
if let Some(js) = store if let Some(js) = store
.get_categories() .fetch_categories()
.await .await
.expect("Failed to get categories.") .expect("Failed to get categories.")
{ {

View File

@ -54,7 +54,7 @@ pub fn Editor<'ctx, G: Html>(cx: Scope<'ctx>, props: RecipeComponentProps<'ctx>)
let store = store.clone(); let store = store.clone();
async move { async move {
let entry = store let entry = store
.get_recipe_text(recipe_id.as_str()) .fetch_recipe_text(recipe_id.as_str())
.await .await
.expect("Failure getting recipe"); .expect("Failure getting recipe");
if let Some(entry) = entry { if let Some(entry) = entry {