From 8bf3b0a290483c2015f90b2fe4283e9a5839695a Mon Sep 17 00:00:00 2001 From: Jadowyne Ulve Date: Sat, 26 Apr 2025 21:04:28 -0500 Subject: [PATCH] recipes_api.saveRecipeItem was updated to new... --- .../database_recipes.cpython-312.pyc | Bin 11757 -> 12879 bytes .../__pycache__/recipes_api.cpython-312.pyc | Bin 17752 -> 17701 bytes scripts/recipes/database_recipes.py | 18 +++++++++++++++++- scripts/recipes/recipes_api.py | 16 +++++++++++----- ...tRecipeUpdate.sql => postUpdateRecipe.sql} | 0 scripts/recipes/sql/postUpdateRecipeItem.sql | 1 + 6 files changed, 29 insertions(+), 6 deletions(-) rename scripts/recipes/sql/{postRecipeUpdate.sql => postUpdateRecipe.sql} (100%) create mode 100644 scripts/recipes/sql/postUpdateRecipeItem.sql diff --git a/scripts/recipes/__pycache__/database_recipes.cpython-312.pyc b/scripts/recipes/__pycache__/database_recipes.cpython-312.pyc index 686a6ced8150d422eab58a8a619920760ac5cb63..5eacd7c357a88d54068e9f6b887620a1b64ae036 100644 GIT binary patch delta 708 zcmaDGeLjWnG%qg~0}zN!;LUg@JCRR<@zF$erFwxB<`%{%mK1>$mQ>ah)>O6>wp8{s zwiNaj)+i2yXc|ij2T+6)C<0WI#+1SdVMg8z#t#f2^4E7(pe#^5r~EHu zHNQSj7Sr^Ze2$%SbD~Na6MK<4&`ni3lOL){#3Q@cvm`Ya?&cy3prRs65Mc!(Y=J~E z50Fqm0!4B_fme>OA3DqODby$Ybsj`TPk}R zTMBy%YZM1UG>s*N11Q1?6alJ9V@lx!^0*N4P+eR=QEm)TZlEX+hA0nElve^nm=`F_ zm%=~sfe1?_lcvCCK1N10t)SH8%!1U=f|SIPRK4QDoFZ1BPpbG-Rf|(g;*)a{ON&!g zRc|q6rf5#KRF7iPr z*Pn^i5$Kf3lYi6%8)EQBPN?^!F|)_qU1pQ+~kVq&M3H{ZdNdzHL-Sbu%LD2i-!@1|2d(S!Fd*9Lo znVKN>=XSeA;NOWW_QO+G?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>4Oj!)tf1Ab;FE3N7%qXi-Ii)3OmDCr+1+jx0=^Fc zrvNJet1R6=kmb=lS=n1aIsLD_r)?p#Gv=XYQ}Q%;?5Sruo5>ZkQc}wlwMx{sruO&2-S)z9Kz$(@d+FsSCLZhfzEnmGaRsPF;G zRbCT_H`dyycymmdyMn$%QD)Ufr2ba}wlZHvWmd6WWEJ~$N0qm-tlFu!9W|4<(^sJ} zn$6M~rfgRlAZZm@$~<~*AETJBDrDU1OnGdvn?NxMBnon+($$XV)e-#J0NFTN8WhVzeekZzw+|f8p*=8b{x& zO{Uim%^BlaV@Wl{=(?y0YhzDraKOKIrm2}YM`FFk$OkoFe%-xj@QY8J;Im42stWWX zccbyk~PBcT3@xx8DM+`m&m;+?Um3TK=AP?fBh|^y@_#gYy SW7drdXp>{uVavn`8u>q9lroh7 diff --git a/scripts/recipes/database_recipes.py b/scripts/recipes/database_recipes.py index 0c03116..0284e1d 100644 --- a/scripts/recipes/database_recipes.py +++ b/scripts/recipes/database_recipes.py @@ -132,11 +132,27 @@ def postUpdateRecipe(site:str, payload:tuple, convert:bool=True): with psycopg2.connect(**database_config) as conn: with conn.cursor() as cur: set_clause, values = postsqldb.updateStringFactory(payload['update']) - with open("scripts/recipes/sql/postRecipeUpdate.sql") as file: + with open("scripts/recipes/sql/postUpdateRecipe.sql") as file: sql = file.read().replace("%%site_name%%", site).replace("%%set_clause%%", set_clause) values.append(payload['id']) cur.execute(sql, values) + rows = cur.fetchone() + if rows and convert: + updated = postsqldb.tupleDictionaryFactory(cur.description, rows) + elif rows and not convert: + updated = rows + return updated +def postUpdateRecipeItem(site:str, payload:tuple, convert:bool=True): + database_config = config.config() + updated = () + with psycopg2.connect(**database_config) as conn: + with conn.cursor() as cur: + set_clause, values = postsqldb.updateStringFactory(payload['update']) + with open("scripts/recipes/sql/postUpdateRecipeItem.sql") as file: + sql = file.read().replace("%%site_name%%", site).replace("%%set_clause%%", set_clause) + values.append(payload['id']) + cur.execute(sql, values) rows = cur.fetchone() if rows and convert: updated = postsqldb.tupleDictionaryFactory(cur.description, rows) diff --git a/scripts/recipes/recipes_api.py b/scripts/recipes/recipes_api.py index 5b8e208..b047a18 100644 --- a/scripts/recipes/recipes_api.py +++ b/scripts/recipes/recipes_api.py @@ -285,15 +285,21 @@ def deleteRecipeItem(): return jsonify({'recipe': recipe, 'error': True, 'message': f'method {request.method} is not allowed!'}) @recipes_api.route('/recipe/saveRecipeItem', methods=["POST"]) +@login_required def saveRecipeItem(): + """ post an update to a recipe item in the database by passing the recipe item ID and an update + payload. + --- + responses: + 200: + description: recipe item updated successfully. + """ recipe = {} if request.method == "POST": id = int(request.get_json()['id']) update = request.get_json()['update'] - database_config = config() site_name = session['selected_site'] - with psycopg2.connect(**database_config) as conn: - updated_line = postsqldb.RecipesTable.update_item_tuple(conn, site_name, {'id': id, 'update': update}, convert=True) - recipe = postsqldb.RecipesTable.getRecipe(conn, site_name, (int(updated_line['rp_id']), ), convert=True) + updated_line = database_recipes.postUpdateRecipeItem(site_name, {'id': id, 'update': update}) + recipe = database_recipes.getRecipe(site_name, (int(updated_line['rp_id']), )) return jsonify({'recipe': recipe, 'error': False, 'message': f'Recipe Item {updated_line['item_name']} was updated successful!'}) - return jsonify({'recipe': recipe, 'error': True, 'message': 'Recipe Item was not updated unsuccessful!'}) \ No newline at end of file + return jsonify({'recipe': recipe, 'error': True, 'message': f'method {request.method} not allowed!'}) \ No newline at end of file diff --git a/scripts/recipes/sql/postRecipeUpdate.sql b/scripts/recipes/sql/postUpdateRecipe.sql similarity index 100% rename from scripts/recipes/sql/postRecipeUpdate.sql rename to scripts/recipes/sql/postUpdateRecipe.sql diff --git a/scripts/recipes/sql/postUpdateRecipeItem.sql b/scripts/recipes/sql/postUpdateRecipeItem.sql new file mode 100644 index 0000000..2d75227 --- /dev/null +++ b/scripts/recipes/sql/postUpdateRecipeItem.sql @@ -0,0 +1 @@ +UPDATE %%site_name%%_recipe_items SET %%set_clause%% WHERE id=%s RETURNING *; \ No newline at end of file