diff --git a/kitchen/sqlx-data.json b/kitchen/sqlx-data.json index a1314ae..5f415aa 100644 --- a/kitchen/sqlx-data.json +++ b/kitchen/sqlx-data.json @@ -172,6 +172,26 @@ }, "query": "insert into category_mappings\n (user_id, ingredient_name, category_name)\n values (?, ?, ?)\n on conflict (user_id, ingredient_name)\n do update set category_name=excluded.category_name\n" }, + "27aa0a21f534cdf580841fa111136fc26cf1a0ca4ddb308c12f3f8f5a62d6178": { + "describe": { + "columns": [], + "nullable": [], + "parameters": { + "Right": 2 + } + }, + "query": "delete from plan_table where user_id = ? and plan_date = ?" + }, + "288535e7b9e1f02ad1b677e3dddc85f38c0766ce16d26fc1bdd2bf90ab9a7f7c": { + "describe": { + "columns": [], + "nullable": [], + "parameters": { + "Right": 2 + } + }, + "query": "insert into plan_table (user_id, plan_date) values (?, ?)\n on conflict (user_id, plan_date) do nothing;" + }, "2e076acd2405d234daaa866e5a2ac1e10989fc8d2820f90aa722464a7b17db6b": { "describe": { "columns": [ diff --git a/kitchen/src/web/storage/mod.rs b/kitchen/src/web/storage/mod.rs index d0a96e8..d2654f6 100644 --- a/kitchen/src/web/storage/mod.rs +++ b/kitchen/src/web/storage/mod.rs @@ -554,6 +554,9 @@ impl APIStore for SqliteStore { ) .execute(&mut transaction) .await?; + sqlx::query_file!("src/web/storage/init_meal_plan.sql", user_id, date) + .execute(&mut transaction) + .await?; for (id, count) in recipe_counts { sqlx::query_file!( "src/web/storage/save_meal_plan.sql", @@ -637,6 +640,13 @@ impl APIStore for SqliteStore { debug!("Processing delete request"); let user_id = user_id.as_ref(); let mut transaction = self.pool.as_ref().begin().await?; + sqlx::query!( + "delete from plan_table where user_id = ? and plan_date = ?", + user_id, + date + ) + .execute(&mut transaction) + .await?; sqlx::query!( "delete from plan_recipes where user_id = ? and plan_date = ?", user_id, diff --git a/web/src/app_state.rs b/web/src/app_state.rs index c51b1d4..4b895e4 100644 --- a/web/src/app_state.rs +++ b/web/src/app_state.rs @@ -504,10 +504,15 @@ impl MessageMapper for StateMachine { .fetch_inventory_for_date(&date) .await .expect("Failed to fetch inventory_data for date"); + original_copy.plan_dates.insert(date.clone()); original_copy.modified_amts = modified; original_copy.filtered_ingredients = filtered; original_copy.extras = extras; local_store.set_plan_date(&date); + store + .store_plan_for_date(vec![], &date) + .await + .expect("Failed to init meal plan for date"); original.set(original_copy);