fixed error on empty poems table
This commit is contained in:
parent
11abdb9147
commit
1a51c580d4
@ -191,6 +191,8 @@ def add_points(user_id: int, db: Annotated[Session, Depends(utils.get_db)]):
|
||||
@app.get("/api/user/poem", response_model=schemas.Poem) # пока не работает
|
||||
def poems_to_front(db: Annotated[Session, Depends(utils.get_db)]): # db: Annotated[Session, Depends(utils.get_db)]
|
||||
num_of_poems = db.query(models.Poems).count() # определяем кол-во стихов в бд
|
||||
if num_of_poems < 1:
|
||||
raise HTTPException(status_code=404, detail="Poems not found")
|
||||
rand_id = random.randint(1, num_of_poems) # генерируем номер стихотворения
|
||||
poem = db.query(models.Poems).filter(models.Poems.id == rand_id).first() # находим стих в бд
|
||||
if not poem:
|
||||
|
Loading…
x
Reference in New Issue
Block a user