aboutsummaryrefslogtreecommitdiff
path: root/gn3
diff options
context:
space:
mode:
authorAlexander_Kabui2024-09-05 13:58:27 +0300
committerAlexander_Kabui2024-09-05 13:58:27 +0300
commit4dc60a7de36134b416d3414bea0c89f49f9420f4 (patch)
tree97503cf765cc9638f5b91300efc70e95665b58b9 /gn3
parenta190f6aa0ddd745e46f6ca059d06a3fca5ffbf2e (diff)
downloadgenenetwork3-4dc60a7de36134b416d3414bea0c89f49f9420f4.tar.gz
Create new endpoints for fetching user previous records.
Diffstat (limited to 'gn3')
-rw-r--r--gn3/api/llm.py72
1 files changed, 51 insertions, 21 deletions
diff --git a/gn3/api/llm.py b/gn3/api/llm.py
index 20831e5..192af23 100644
--- a/gn3/api/llm.py
+++ b/gn3/api/llm.py
@@ -84,32 +84,62 @@ def rate_queries(task_id):
}, 200
-@gnqa.route("/history", methods=["GET", "DELETE"])
+@gnqa.route("/search/records", methods=["GET"])
@require_oauth("profile user")
-def fetch_prev_history():
- """Api endpoint to fetch GNQA previous search."""
+def get_user_search_records():
+ """get all history records for a given user using their
+ user id
+ """
with (require_oauth.acquire("profile user") as token,
db.connection(current_app.config["LLM_DB_PATH"]) as conn):
cursor = conn.cursor()
- if request.method == "DELETE":
- 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({})
- elif (request.method == "GET" and
- request.args.get("search_term")):
- cursor.execute(
- """SELECT results from history
- Where task_id=? and user_id=?""",
- (request.args.get("search_term"),
- str(token.user.user_id),))
- record = cursor.fetchone()
- if record:
- return dict(record).get("results")
- return {}
cursor.execute(
"""SELECT task_id,query from history WHERE user_id=?""",
(str(token.user.user_id),))
return jsonify([dict(item) for item in cursor.fetchall()])
+
+
+@gnqa.route("/search/record/<task_id>", methods=["GET"])
+@require_oauth("profile user")
+def get_user_record_by_task(task_id):
+ """Get user record by task id """
+ with (require_oauth.acquire("profile user") as token,
+ db.connection(current_app.config["LLM_DB_PATH"]) as conn):
+ cursor = conn.cursor()
+ cursor.execute(
+ """SELECT results from history
+ Where task_id=? and user_id=?""",
+ (task_id,
+ str(token.user.user_id),))
+ record = cursor.fetchone()
+ if record:
+ return dict(record).get("results")
+ return {}
+
+
+@gnqa.route("/search/record/<task_id>", methods=["DELETE"])
+@require_oauth("profile user")
+def delete_record(task_id):
+ """Delete user record by task-id"""
+ with (require_oauth.acquire("profile user") as token,
+ db.connection(current_app.config["LLM_DB_PATH"]) as conn):
+ cursor = conn.cursor()
+ query = """DELETE FROM history
+ WHERE task_id=? and user_id=?"""
+ cursor.execute(query, (task_id, token.user.user_id,))
+ return {"msg": f"Successfully Deleted the task {task_id}"}
+
+
+@gnqa.route("/search/records", methods=["DELETE"])
+@require_oauth("profile user")
+def delete_records():
+ """ Delete a users records using for all given task ids"""
+ with (require_oauth.acquire("profile user") as token,
+ db.connection(current_app.config["LLM_DB_PATH"]) as conn):
+ task_ids = list(request.json.values())
+ cursor = conn.cursor()
+ 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({})