test
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2026-05-03 13:48:49 +10:00
parent 8f86c51d19
commit 0577f4d65c
2 changed files with 7 additions and 4 deletions

View File

@@ -50,8 +50,8 @@ def setup_routes(app: FastAPI) -> None:
return {"status": "success", "message": "Источник добавлен", "data": result} return {"status": "success", "message": "Источник добавлен", "data": result}
@app.get("/all_sources", summary="Метод получения всех источников") @app.get("/all_sources", summary="Метод получения всех источников")
async def get_all_sources(): async def get_all_sources(category: str = "all"):
return wp.get_all_sources() return wp.get_all_sources(category)
@app.delete("/delete_sources", summary="Метод удаления источника") @app.delete("/delete_sources", summary="Метод удаления источника")
async def delete_sources(url: str): async def delete_sources(url: str):

View File

@@ -345,12 +345,15 @@ def add_sources(url: str, promt: str):
finally: finally:
pass pass
def get_all_sources(): def get_all_sources(category: str):
"""Возвращает все записи из таблицы sourse""" """Возвращает все записи из таблицы sourse"""
conn = get_connection() conn = get_connection()
try: try:
with conn.cursor(cursor_factory=RealDictCursor) as cur: with conn.cursor(cursor_factory=RealDictCursor) as cur:
if category == "all":
cur.execute("SELECT * FROM sourse") cur.execute("SELECT * FROM sourse")
else:
cur.execute("SELECT * FROM sourse WHERE category = %s", (category,))
rows = cur.fetchall() rows = cur.fetchall()
sources = [{"url": row["url"], "promt": row["promt"]} for row in rows] sources = [{"url": row["url"], "promt": row["promt"]} for row in rows]
return {"sources": sources} return {"sources": sources}