diff --git a/scripts/recipes/__pycache__/database_recipes.cpython-312.pyc b/scripts/recipes/__pycache__/database_recipes.cpython-312.pyc index f923b9d..8d297b8 100644 Binary files a/scripts/recipes/__pycache__/database_recipes.cpython-312.pyc and b/scripts/recipes/__pycache__/database_recipes.cpython-312.pyc differ diff --git a/scripts/recipes/__pycache__/recipes_api.cpython-312.pyc b/scripts/recipes/__pycache__/recipes_api.cpython-312.pyc index e8e41da..605321d 100644 Binary files a/scripts/recipes/__pycache__/recipes_api.cpython-312.pyc and b/scripts/recipes/__pycache__/recipes_api.cpython-312.pyc differ diff --git a/scripts/recipes/database_recipes.py b/scripts/recipes/database_recipes.py index 4f02266..89d7bd9 100644 --- a/scripts/recipes/database_recipes.py +++ b/scripts/recipes/database_recipes.py @@ -81,7 +81,15 @@ def getRecipe(site, payload:tuple, convert=True): return record except (Exception, psycopg2.DatabaseError) as error: raise postsqldb.DatabaseError(error, payload, sql) - + +def getPicturePath(site:str, payload:tuple, convert:bool=True): + database_config = config.config() + with psycopg2.connect(**database_config) as conn: + with conn.cursor() as cur: + cur.execute(f"SELECT picture_path FROM {site}_recipes WHERE id=%s;", payload) + rows = cur.fetchone()[0] + return rows + def postRecipe(site:str, payload:tuple, convert=True): database_config = config.config() record = () diff --git a/scripts/recipes/recipes_api.py b/scripts/recipes/recipes_api.py index 06e78c0..c2632bf 100644 --- a/scripts/recipes/recipes_api.py +++ b/scripts/recipes/recipes_api.py @@ -5,7 +5,6 @@ from main import unfoldCostLayers from user_api import login_required import os import postsqldb, webpush -from flasgger import swag_from from scripts.recipes import database_recipes from scripts import postsqldb as db from flask_restx import Api, fields @@ -249,14 +248,23 @@ def uploadImage(recipe_id): return jsonify({'error': False, 'message': 'Recipe was updated successfully!'}) @recipes_api.route('/recipe/getImage/') +@login_required def get_image(recipe_id): - database_config = config() + """ get the picture path for a recipe by passing teh recipe id in the path + --- + parameters: + - name: recipe_id + in: path + required: true + schema: + type: integer + responses: + 200: + description: image fetched succesfully! + """ site_name = session['selected_site'] - with psycopg2.connect(**database_config) as conn: - with conn.cursor() as cur: - cur.execute(f"SELECT picture_path FROM {site_name}_recipes WHERE id=%s;", (recipe_id,)) - rows = cur.fetchone()[0] - return send_from_directory('static/pictures/recipes', rows) + picture_path = database_recipes.getPicturePath(site_name, (recipe_id,)) + return send_from_directory('static/pictures/recipes', picture_path) @recipes_api.route('/recipe/deleteRecipeItem', methods=["POST"]) def deleteRecipeItem():