mirror of
https://github.com/zaphar/kitchen.git
synced 2025-07-21 19:29:49 -04:00
API naming consistency get_ -> fetch_
This commit is contained in:
parent
19c75930cc
commit
30293878fc
@ -372,7 +372,7 @@ impl HttpStore {
|
||||
}
|
||||
|
||||
#[instrument]
|
||||
pub async fn get_user_data(&self) -> Option<UserData> {
|
||||
pub async fn fetch_user_data(&self) -> Option<UserData> {
|
||||
debug!("Retrieving User Account data");
|
||||
let mut path = self.v2_path();
|
||||
path.push_str("/account");
|
||||
@ -393,7 +393,7 @@ impl HttpStore {
|
||||
return None;
|
||||
}
|
||||
//#[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();
|
||||
path.push_str("/categories");
|
||||
let resp = match reqwasm::http::Request::get(&path).send().await {
|
||||
@ -419,7 +419,7 @@ impl HttpStore {
|
||||
}
|
||||
|
||||
#[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();
|
||||
path.push_str("/recipes");
|
||||
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,
|
||||
id: S,
|
||||
) -> 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();
|
||||
path.push_str("/plan");
|
||||
let resp = reqwasm::http::Request::get(&path).send().await?;
|
||||
@ -576,6 +576,7 @@ impl HttpStore {
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn fetch_inventory_data(
|
||||
&self,
|
||||
) -> Result<
|
||||
(
|
||||
|
@ -153,6 +153,7 @@ impl StateMachine {
|
||||
) -> Result<(), crate::api::Error> {
|
||||
let mut state = original.get().as_ref().clone();
|
||||
info!("Synchronizing Recipes");
|
||||
let recipe_entries = &store.fetch_recipes().await?;
|
||||
let (staples, recipes) = filter_recipes(&recipe_entries)?;
|
||||
if let Some(recipes) = recipes {
|
||||
state.staples = staples;
|
||||
@ -162,6 +163,7 @@ impl StateMachine {
|
||||
local_store.set_all_recipes(recipe_entries);
|
||||
}
|
||||
|
||||
let plan = store.fetch_plan().await?;
|
||||
if let Some(plan) = plan {
|
||||
// set the counts.
|
||||
let mut plan_map = BTreeMap::new();
|
||||
@ -184,6 +186,7 @@ impl StateMachine {
|
||||
.collect::<Vec<(String, i32)>>();
|
||||
local_store.save_plan(&plan);
|
||||
info!("Checking for user account data");
|
||||
if let Some(user_data) = store.fetch_user_data().await {
|
||||
debug!("Successfully got account data from server");
|
||||
local_store.set_user_data(Some(&user_data));
|
||||
state.auth = Some(user_data);
|
||||
@ -193,6 +196,7 @@ impl StateMachine {
|
||||
state.auth = user_data;
|
||||
}
|
||||
info!("Synchronizing categories");
|
||||
match store.fetch_categories().await {
|
||||
Ok(Some(categories_content)) => {
|
||||
debug!(categories=?categories_content);
|
||||
local_store.set_categories(Some(&categories_content));
|
||||
@ -207,6 +211,7 @@ impl StateMachine {
|
||||
}
|
||||
}
|
||||
info!("Synchronizing inventory data");
|
||||
match store.fetch_inventory_data().await {
|
||||
Ok((filtered_ingredients, modified_amts, extra_items)) => {
|
||||
local_store.set_inventory_data((
|
||||
&filtered_ingredients,
|
||||
|
@ -63,7 +63,7 @@ pub fn AddRecipe<'ctx, G: Html>(cx: Scope<'ctx>, sh: StateHandler<'ctx>) -> View
|
||||
async move {
|
||||
let entry = entry.get_untracked();
|
||||
// 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(_)) => {
|
||||
// TODO(jwall): We should tell the user that this id already exists
|
||||
info!(recipe_id = entry.recipe_id(), "Recipe already exists");
|
||||
|
@ -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);
|
||||
async move {
|
||||
if let Some(js) = store
|
||||
.get_categories()
|
||||
.fetch_categories()
|
||||
.await
|
||||
.expect("Failed to get categories.")
|
||||
{
|
||||
|
@ -54,7 +54,7 @@ pub fn Editor<'ctx, G: Html>(cx: Scope<'ctx>, props: RecipeComponentProps<'ctx>)
|
||||
let store = store.clone();
|
||||
async move {
|
||||
let entry = store
|
||||
.get_recipe_text(recipe_id.as_str())
|
||||
.fetch_recipe_text(recipe_id.as_str())
|
||||
.await
|
||||
.expect("Failure getting recipe");
|
||||
if let Some(entry) = entry {
|
||||
|
Loading…
x
Reference in New Issue
Block a user