From e95ca870b1eb35d9bd1994f95006d040cbbcc018 Mon Sep 17 00:00:00 2001 From: Hayden <64056131+hay-kot@users.noreply.github.com> Date: Sat, 12 Jun 2021 22:23:23 -0800 Subject: [PATCH] Add Database Layer for Recipe Scaling (#506) * move badge * fix add individual ingredient * fix redirect issue Co-authored-by: hay-kot --- frontend/src/api/api-utils.js | 5 + frontend/src/api/recipe.js | 8 +- .../src/components/Recipe/ContextMenu.vue | 24 ++--- .../src/components/Recipe/FavoriteBadge.vue | 2 +- .../components/Recipe/Parts/Ingredients.vue | 27 +++++- frontend/src/pages/Recipe/ViewRecipe.vue | 8 +- frontend/src/pages/ShoppingList/index.vue | 26 +++--- frontend/src/routes/recipes.js | 3 +- makefile | 2 +- mealie/db/database.py | 41 ++++++-- mealie/db/models/recipe/ingredient.py | 93 +++++++++++++++++-- mealie/db/models/recipe/recipe.py | 2 +- mealie/routes/mealplans/helpers.py | 2 +- mealie/routes/recipe/recipe_crud_routes.py | 3 + mealie/routes/unit_and_foods/__init__.py | 8 ++ mealie/routes/unit_and_foods/food_routes.py | 34 +++++++ mealie/routes/unit_and_foods/unit_routes.py | 34 +++++++ mealie/schema/recipe.py | 38 +++++++- 18 files changed, 298 insertions(+), 62 deletions(-) create mode 100644 mealie/routes/unit_and_foods/__init__.py create mode 100644 mealie/routes/unit_and_foods/food_routes.py create mode 100644 mealie/routes/unit_and_foods/unit_routes.py diff --git a/frontend/src/api/api-utils.js b/frontend/src/api/api-utils.js index 8f83a4094..012f5bd0a 100644 --- a/frontend/src/api/api-utils.js +++ b/frontend/src/api/api-utils.js @@ -31,6 +31,7 @@ const apiReq = { post: async function(url, data, getErrorText = defaultErrorText, getSuccessText) { const response = await axios.post(url, data).catch(function(error) { handleError(error, getErrorText); + return error; }); return handleResponse(response, getSuccessText); }, @@ -38,6 +39,7 @@ const apiReq = { put: async function(url, data, getErrorText = defaultErrorText, getSuccessText) { const response = await axios.put(url, data).catch(function(error) { handleError(error, getErrorText); + return error; }); return handleResponse(response, getSuccessText); }, @@ -45,6 +47,7 @@ const apiReq = { patch: async function(url, data, getErrorText = defaultErrorText, getSuccessText) { const response = await axios.patch(url, data).catch(function(error) { handleError(error, getErrorText); + return error; }); return handleResponse(response, getSuccessText); }, @@ -52,12 +55,14 @@ const apiReq = { get: async function(url, data, getErrorText = defaultErrorText) { return axios.get(url, data).catch(function(error) { handleError(error, getErrorText); + return error; }); }, delete: async function(url, data, getErrorText = defaultErrorText, getSuccessText = defaultSuccessText) { const response = await axios.delete(url, data).catch(function(error) { handleError(error, getErrorText); + return error; }); return handleResponse(response, getSuccessText); }, diff --git a/frontend/src/api/recipe.js b/frontend/src/api/recipe.js index ac4e5fb86..7f039e32b 100644 --- a/frontend/src/api/recipe.js +++ b/frontend/src/api/recipe.js @@ -35,9 +35,11 @@ export const recipeAPI = { }, async requestDetails(recipeSlug) { - let response = await apiReq.get(API_ROUTES.recipesRecipeSlug(recipeSlug)); - if (response && response.data) return response.data; - else return null; + const response = await apiReq.get(API_ROUTES.recipesRecipeSlug(recipeSlug)); + if (response.response) { + return response.response; + } + return response; }, updateImage(recipeSlug, fileObject, overrideSuccessMsg = false) { diff --git a/frontend/src/components/Recipe/ContextMenu.vue b/frontend/src/components/Recipe/ContextMenu.vue index c58a670a3..8cde1278f 100644 --- a/frontend/src/components/Recipe/ContextMenu.vue +++ b/frontend/src/components/Recipe/ContextMenu.vue @@ -16,25 +16,13 @@ :top="menuTop" :nudge-top="menuTop ? '5' : '0'" allow-overflow + close-delay="125" + open-on-hover > -