Change rating and dispose endpoints fixed

This commit is contained in:
2023-08-08 23:41:54 +03:00
parent 15d61ecc4b
commit 0c47da5543
5 changed files with 90 additions and 15 deletions

View File

@ -183,6 +183,8 @@ def add_points(data: schemas.AddRating, current_user: Annotated[schemas.User, De
raise HTTPException(status_code=404, detail="Item not found")
user.rating = (user.rating*user.num_of_ratings + data.rate)/(user.num_of_ratings + 1)
user.num_of_ratings += 1
database.commit()
database.refresh(user) # обновляем состояние объекта
return {"Success": True}
@ -245,11 +247,12 @@ async def react_app(req: Request, rest_of_path: str):
return templates.TemplateResponse('index.html', { 'request': req })
@app.post("api/announcement/dispose")
def dispose(data: schemas.TrashboxResponse, current_user: Annotated[schemas.User, Depends(utils.get_current_user)]):
@app.post("/api/announcement/dispose")
def dispose(data: schemas.DisposeRequest, current_user_schema: Annotated[schemas.User, Depends(utils.get_current_user)]):
current_user = utils.get_user_by_id(database, current_user_schema.id)
current_user.points += 60
new_trashox = models.Trashbox(user_id=current_user.id, date_of_chose=datetime.date.today(), name=data.Name,
latitude=data.Lat, longtitude=data.Lng, address=data.Address, category=data.Categories)
new_trashox = models.Trashbox(user_id=current_user.id, date_of_choice=datetime.date.today(), name=data.Name,
latitude=data.Lat, longtitude=data.Lng, address=data.Address, categories=data.Categories)
database.add(new_trashox)
database.commit()
database.refresh(new_trashox) # обновляем состояние объекта