убрал parser_bd
This commit is contained in:
@@ -180,79 +180,3 @@ def setup_routes(app: FastAPI) -> None:
|
||||
with open("app.log", "r") as file:
|
||||
lines = file.readlines()[-10:]
|
||||
return {"logs": lines}
|
||||
|
||||
# ==================== Эндпоинты из parser_bd.py ====================
|
||||
|
||||
@app.post("/save_parsed_data", summary="Сохранить данные парсинга")
|
||||
def save_parsed_data(data: pbd.ParsedData):
|
||||
try:
|
||||
pbd.save_parsed_data_to_db(data)
|
||||
return {"status": "success", "message": "Данные успешно сохранены"}
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=500, detail=f"Ошибка при сохранении данных: {e}")
|
||||
|
||||
@app.post("/update_viewed_status", summary="Обновляет поле viewed")
|
||||
def update_viewed_status(url: str, viewed: bool):
|
||||
try:
|
||||
result = pbd.update_viewed_status_in_db(url, viewed)
|
||||
if not result.get("found"):
|
||||
raise HTTPException(status_code=404, detail="Запись с указанным URL не найдена")
|
||||
except Exception as e:
|
||||
if isinstance(e, HTTPException):
|
||||
raise e
|
||||
raise HTTPException(status_code=500, detail=f"Ошибка при сохранении данных: {e}")
|
||||
return {"status": "success", "message": "Статус просмотра успешно обновлен"}
|
||||
|
||||
@app.post("/update_status_status", summary="Обновляет поле status")
|
||||
def update_status_status(url: str, status: bool):
|
||||
try:
|
||||
result = pbd.update_status_status_in_db(url, status)
|
||||
if not result.get("found"):
|
||||
raise HTTPException(status_code=404, detail="Запись с указанным URL не найдена")
|
||||
except Exception as e:
|
||||
if isinstance(e, HTTPException):
|
||||
raise e
|
||||
raise HTTPException(status_code=500, detail=f"Ошибка при сохранении данных: {e}")
|
||||
return {"status": "success", "message": "Статус просмотра успешно обновлен"}
|
||||
|
||||
@app.get("/check_url_exists", summary="Проверяет url")
|
||||
def check_url_exists(url: str):
|
||||
try:
|
||||
return pbd.check_url_exists_in_db(url)
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=500, detail=f"Ошибка при проверке: {e}")
|
||||
|
||||
@app.get("/records", summary="Получить записи из БД с пагинацией", response_model=List[pbd.ParsedData])
|
||||
def get_records(offset: int = Query(0, ge=0), limit: int = Query(10, ge=1, le=100)):
|
||||
try:
|
||||
return pbd.get_records_from_db(offset, limit)
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=500, detail=f"Ошибка при получении записей из БД: {e}")
|
||||
|
||||
@app.get("/records_all/count", summary="Получить общее количество записей")
|
||||
def get_records_count(item: str = Query("default")):
|
||||
try:
|
||||
return pbd.get_records_count_from_db(item)
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=500, detail=f"Ошибка при получении количества: {e}")
|
||||
|
||||
@app.get("/poisk/count", summary="Получить количество результатов поиска")
|
||||
def get_poisk_count(query: str, item: str = Query("default")):
|
||||
try:
|
||||
return pbd.get_poisk_count_from_db(query, item)
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=500, detail=f"Ошибка при получении количества: {e}")
|
||||
|
||||
@app.get("/poisk", summary="Поиск с пагинацией")
|
||||
def poisk(query: str, offset: int = Query(0, ge=0), limit: int = Query(10, ge=1, le=100), item: str = Query("default")):
|
||||
try:
|
||||
return pbd.poisk_from_db(query, offset, limit, item)
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=500, detail=f"Ошибка при поиске: {e}")
|
||||
|
||||
@app.get("/records_all", summary="Получить все записи из БД + сортирует + пагинация", response_model=List[pbd.ParsedData])
|
||||
def get_records_all(item: str = Query("default"), offset: int = Query(0, ge=0), limit: int = Query(10, ge=1, le=100)):
|
||||
try:
|
||||
return pbd.get_records_all_from_db(item, offset, limit)
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=500, detail=f"Ошибка при получении записей из БД: {e}")
|
||||
|
||||
Reference in New Issue
Block a user