diff options
author | Alexander_Kabui | 2024-09-05 15:27:00 +0300 |
---|---|---|
committer | Alexander_Kabui | 2024-09-05 15:27:00 +0300 |
commit | 8cb85c8f8c12180702cfc3a257bf9a513ac4da3d (patch) | |
tree | 5004a07f51135229a12f6ef64280501c5c94d8b8 | |
parent | 57986c976c702c590cc814fa9863c4fd9be42c6f (diff) | |
download | genenetwork3-8cb85c8f8c12180702cfc3a257bf9a513ac4da3d.tar.gz |
Sort previos records by datetime.
-rw-r--r-- | gn3/api/llm.py | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/gn3/api/llm.py b/gn3/api/llm.py index cdf427e..7e60271 100644 --- a/gn3/api/llm.py +++ b/gn3/api/llm.py @@ -1,5 +1,7 @@ """Api endpoints for gnqa""" import json +from datetime import datetime + from flask import Blueprint from flask import current_app from flask import jsonify @@ -94,15 +96,18 @@ def get_user_search_records(): db.connection(current_app.config["LLM_DB_PATH"]) as conn): cursor = conn.cursor() cursor.execute( - """SELECT task_id,query from history WHERE user_id=?""", + """SELECT task_id, query, created_at from history WHERE user_id=?""", (str(token.user.user_id),)) - return jsonify([dict(item) for item in cursor.fetchall()]) + results = [dict(item) for item in cursor.fetchall()] + return jsonify(sorted(results, reverse=True, + key=lambda x: datetime.strptime(x.get("created_at"), + '%Y-%m-%d %H:%M:%S'))) @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 """ + """Get user previous search 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() @@ -120,7 +125,7 @@ def get_user_record_by_task(task_id): @gnqa.route("/search/record/<task_id>", methods=["DELETE"]) @require_oauth("profile user") def delete_record(task_id): - """Delete user record by task-id""" + """Delete user previous seach 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() |