aboutsummaryrefslogtreecommitdiff
path: root/gn3/api
diff options
context:
space:
mode:
authorAlexander_Kabui2024-05-29 14:05:00 +0300
committerAlexander_Kabui2024-05-29 14:28:45 +0300
commit7d79812db623d12474422a9613c81f35e25aef55 (patch)
treedeb8ab4889bf5111dc70f703599115f39402bfd8 /gn3/api
parentd3f87b9a02bfec223d23c16eb1374d53065fea92 (diff)
downloadgenenetwork3-7d79812db623d12474422a9613c81f35e25aef55.tar.gz
Add delete functionality for gnqa history.
Diffstat (limited to 'gn3/api')
-rw-r--r--gn3/api/llm.py12
1 files changed, 10 insertions, 2 deletions
diff --git a/gn3/api/llm.py b/gn3/api/llm.py
index 4b8ec52..228d3fa 100644
--- a/gn3/api/llm.py
+++ b/gn3/api/llm.py
@@ -86,16 +86,24 @@ def rate_queries(task_id):
}, 200
-@gnqa.route("/history", methods=["GET"])
+@gnqa.route("/history", methods=["GET", "POST"])
@require_oauth("profile user")
def fetch_prev_history():
"""Api endpoint to fetch GNQA previous search."""
with (require_oauth.acquire("profile user") as token,
db.connection(current_app.config["LLM_DB_PATH"]) as conn):
cursor = conn.cursor()
+ if request.method == "POST":
+ task_ids = list(request.json.values())
+ query = """DELETE FROM history
+ WHERE task_id IN ({})
+ and user_id=?""".format(",".join("?" * len(task_ids)))
+ cursor.execute(query, (*task_ids, str(token.user.user_id),))
+ return jsonify({})
if request.args.get("search_term"):
cursor.execute(
- """SELECT results from history Where task_id=? and user_id=?""",
+ """SELECT results from history
+ Where task_id=? and user_id=?""",
(request.args.get("search_term"),
str(token.user.user_id),))
return dict(cursor.fetchone())["results"]