From 1c7e95b11918cb129d51c7da5dec6dca4d0d5214 Mon Sep 17 00:00:00 2001 From: n0body Date: Sat, 6 Sep 2025 02:45:47 +0300 Subject: [PATCH] Fixes - /api/rates endpoint now returns a list of entries in a json form --- src/DBwork.py | 10 +++++++--- src/router.py | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/DBwork.py b/src/DBwork.py index 2692688..74824fa 100644 --- a/src/DBwork.py +++ b/src/DBwork.py @@ -53,9 +53,14 @@ def delete_entry(article_url, connection): def get_all_entries(connection): try: cursor = connection.cursor() - cursor.execute('SELECT article_url, rating FROM harticle.articles;') - entries = cursor.fetchall() + cursor.execute('SELECT article_url FROM harticle.articles;') + urls = cursor.fetchall() + cursor.execute('SELECT rating FROM harticle.articles;') + ratings = cursor.fetchall() logger.info('All entry pairs have been retrieved successfully') + entries = {} + for i in range(len(urls)): + entries[urls[i][0]] = ratings[i][0] return entries except psycopg2.Error as e: logger.error(f'Failed to fetch DB entries: {e.pgerror}') @@ -93,4 +98,3 @@ def table_creator(schema_name, table_name, connection): logger.info(f'Successfully created table {table_name} in schema {schema_name} if it didn\'t exist yet') except psycopg2.Error as e: logger.error(f'Error during table creation: {e}') - diff --git a/src/router.py b/src/router.py index 63accee..060f7ea 100644 --- a/src/router.py +++ b/src/router.py @@ -31,7 +31,7 @@ async def ping(): @router.get('/rates') async def get_rates(): - result = dumps(DBwork.get_all_entries(db.connection)) + result = DBwork.get_all_entries(db.connection) return result