diff --git a/api/routes.py b/api/routes.py index f198b63..e3b2ff5 100644 --- a/api/routes.py +++ b/api/routes.py @@ -50,8 +50,8 @@ def setup_routes(app: FastAPI) -> None: return {"status": "success", "message": "Источник добавлен", "data": result} @app.get("/all_sources", summary="Метод получения всех источников") - async def get_all_sources(): - return wp.get_all_sources() + async def get_all_sources(category: str = "all"): + return wp.get_all_sources(category) @app.delete("/delete_sources", summary="Метод удаления источника") async def delete_sources(url: str): diff --git a/work_parser.py b/work_parser.py index e36003e..2facadb 100644 --- a/work_parser.py +++ b/work_parser.py @@ -345,12 +345,15 @@ def add_sources(url: str, promt: str): finally: pass -def get_all_sources(): +def get_all_sources(category: str): """Возвращает все записи из таблицы sourse""" conn = get_connection() try: with conn.cursor(cursor_factory=RealDictCursor) as cur: - cur.execute("SELECT * FROM sourse") + if category == "all": + cur.execute("SELECT * FROM sourse") + else: + cur.execute("SELECT * FROM sourse WHERE category = %s", (category,)) rows = cur.fetchall() sources = [{"url": row["url"], "promt": row["promt"]} for row in rows] return {"sources": sources}