This commit is contained in:
2023-08-12 12:42:52 +03:00
16 changed files with 177 additions and 166 deletions

View File

@ -191,17 +191,14 @@ def add_points(user_id: int, db: Annotated[Session, Depends(utils.get_db)]):
# Отправляем стихи
@app.get("/api/user/poem") # пока не работает
@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)]
kolvo_stixov = db.query(models.Poems).count() # пока количество стихотворений = 101
if kolvo_stixov > 1:
rand_id = random.randint(1, kolvo_stixov) # номер стихотворения
poem_json = dict()
poem = db.query(models.Poems).filter(models.Poems.id == rand_id).first()
poem_json = {"id": rand_id, "title": poem.title, "text": poem.text, "author": poem.author}
return poem_json
else:
raise HTTPException(status_code=404, detail="Poems not found")
num_of_poems = db.query(models.Poems).count() # определяем кол-во стихов в бд
rand_id = random.randint(1, num_of_poems) # генерируем номер стихотворения
poem = db.query(models.Poems).filter(models.Poems.id == rand_id).first() # находим стих в бд
if not poem:
raise HTTPException(status_code=404, detail="Poem not found")
return poem
@app.get("/api/trashbox", response_model=List[schemas.TrashboxResponse])