mirror of
https://github.com/zaphar/kitchen.git
synced 2025-07-21 19:29:49 -04:00
Remove calls to the v1 api.
This commit is contained in:
parent
8b689bfdf5
commit
19c75930cc
@ -328,12 +328,6 @@ impl HttpStore {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn v1_path(&self) -> String {
|
||||
let mut path = self.root.clone();
|
||||
path.push_str("/v1");
|
||||
path
|
||||
}
|
||||
|
||||
pub fn v2_path(&self) -> String {
|
||||
let mut path = self.root.clone();
|
||||
path.push_str("/v2");
|
||||
@ -352,7 +346,7 @@ impl HttpStore {
|
||||
#[instrument(skip_all, fields(?self, user))]
|
||||
pub async fn authenticate(&self, user: String, pass: String) -> Option<UserData> {
|
||||
debug!("attempting login request against api.");
|
||||
let mut path = self.v1_path();
|
||||
let mut path = self.v2_path();
|
||||
path.push_str("/auth");
|
||||
let result = reqwasm::http::Request::get(&path)
|
||||
.header(
|
||||
@ -400,7 +394,7 @@ impl HttpStore {
|
||||
}
|
||||
//#[instrument]
|
||||
pub async fn get_categories(&self) -> Result<Option<String>, Error> {
|
||||
let mut path = self.v1_path();
|
||||
let mut path = self.v2_path();
|
||||
path.push_str("/categories");
|
||||
let resp = match reqwasm::http::Request::get(&path).send().await {
|
||||
Ok(resp) => resp,
|
||||
@ -426,7 +420,7 @@ impl HttpStore {
|
||||
|
||||
#[instrument]
|
||||
pub async fn get_recipes(&self) -> Result<Option<Vec<RecipeEntry>>, Error> {
|
||||
let mut path = self.v1_path();
|
||||
let mut path = self.v2_path();
|
||||
path.push_str("/recipes");
|
||||
let resp = match reqwasm::http::Request::get(&path).send().await {
|
||||
Ok(resp) => resp,
|
||||
@ -455,7 +449,7 @@ impl HttpStore {
|
||||
&self,
|
||||
id: S,
|
||||
) -> Result<Option<RecipeEntry>, Error> {
|
||||
let mut path = self.v1_path();
|
||||
let mut path = self.v2_path();
|
||||
path.push_str("/recipe/");
|
||||
path.push_str(id.as_ref());
|
||||
let resp = match reqwasm::http::Request::get(&path).send().await {
|
||||
@ -490,7 +484,7 @@ impl HttpStore {
|
||||
|
||||
#[instrument(skip(recipes), fields(count=recipes.len()))]
|
||||
pub async fn save_recipes(&self, recipes: Vec<RecipeEntry>) -> Result<(), Error> {
|
||||
let mut path = self.v1_path();
|
||||
let mut path = self.v2_path();
|
||||
path.push_str("/recipes");
|
||||
for r in recipes.iter() {
|
||||
if r.recipe_id().is_empty() {
|
||||
@ -513,7 +507,7 @@ impl HttpStore {
|
||||
|
||||
#[instrument(skip(categories))]
|
||||
pub async fn save_categories(&self, categories: String) -> Result<(), Error> {
|
||||
let mut path = self.v1_path();
|
||||
let mut path = self.v2_path();
|
||||
path.push_str("/categories");
|
||||
let resp = reqwasm::http::Request::post(&path)
|
||||
.body(to_string(&categories).expect("Unable to encode categories as json"))
|
||||
@ -550,7 +544,7 @@ impl HttpStore {
|
||||
}
|
||||
|
||||
pub async fn save_plan(&self, plan: Vec<(String, i32)>) -> Result<(), Error> {
|
||||
let mut path = self.v1_path();
|
||||
let mut path = self.v2_path();
|
||||
path.push_str("/plan");
|
||||
let resp = reqwasm::http::Request::post(&path)
|
||||
.body(to_string(&plan).expect("Unable to encode plan as json"))
|
||||
@ -566,7 +560,7 @@ impl HttpStore {
|
||||
}
|
||||
|
||||
pub async fn get_plan(&self) -> Result<Option<Vec<(String, i32)>>, Error> {
|
||||
let mut path = self.v1_path();
|
||||
let mut path = self.v2_path();
|
||||
path.push_str("/plan");
|
||||
let resp = reqwasm::http::Request::get(&path).send().await?;
|
||||
if resp.status() != 200 {
|
||||
@ -582,7 +576,6 @@ impl HttpStore {
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn get_inventory_data(
|
||||
&self,
|
||||
) -> Result<
|
||||
(
|
||||
|
@ -153,7 +153,6 @@ impl StateMachine {
|
||||
) -> Result<(), crate::api::Error> {
|
||||
let mut state = original.get().as_ref().clone();
|
||||
info!("Synchronizing Recipes");
|
||||
let recipe_entries = &store.get_recipes().await?;
|
||||
let (staples, recipes) = filter_recipes(&recipe_entries)?;
|
||||
if let Some(recipes) = recipes {
|
||||
state.staples = staples;
|
||||
@ -163,7 +162,6 @@ impl StateMachine {
|
||||
local_store.set_all_recipes(recipe_entries);
|
||||
}
|
||||
|
||||
let plan = store.get_plan().await?;
|
||||
if let Some(plan) = plan {
|
||||
// set the counts.
|
||||
let mut plan_map = BTreeMap::new();
|
||||
@ -186,7 +184,6 @@ impl StateMachine {
|
||||
.collect::<Vec<(String, i32)>>();
|
||||
local_store.save_plan(&plan);
|
||||
info!("Checking for user account data");
|
||||
if let Some(user_data) = store.get_user_data().await {
|
||||
debug!("Successfully got account data from server");
|
||||
local_store.set_user_data(Some(&user_data));
|
||||
state.auth = Some(user_data);
|
||||
@ -196,7 +193,6 @@ impl StateMachine {
|
||||
state.auth = user_data;
|
||||
}
|
||||
info!("Synchronizing categories");
|
||||
match store.get_categories().await {
|
||||
Ok(Some(categories_content)) => {
|
||||
debug!(categories=?categories_content);
|
||||
local_store.set_categories(Some(&categories_content));
|
||||
@ -211,7 +207,6 @@ impl StateMachine {
|
||||
}
|
||||
}
|
||||
info!("Synchronizing inventory data");
|
||||
match store.get_inventory_data().await {
|
||||
Ok((filtered_ingredients, modified_amts, extra_items)) => {
|
||||
local_store.set_inventory_data((
|
||||
&filtered_ingredients,
|
||||
|
Loading…
x
Reference in New Issue
Block a user