diff --git a/backend/db/crud.py b/backend/db/crud.py index d855220d2a12cfd95da2029d8e63b389ba2e8908..77f677b9b3d1d48e545e484b5753f84df1ef1cf2 100644 --- a/backend/db/crud.py +++ b/backend/db/crud.py @@ -21,14 +21,15 @@ def get_waiting_time(place: str, db: Session): data["next_timetable"] = "{:d}h{:02d}".format(first_timeslot[0].hour, first_timeslot[0].minute) return data elif first_timeslot and current_time <= first_timeslot[1]: - waiting_time = db.query( + last_record = db.query( models.Records.waiting_time ).filter( models.Records.place == place ).order_by( models.Records.date.desc() ).first() - if waiting_time: + if last_record: + waiting_time = last_record.waiting_time waiting_time = round(waiting_time.total_seconds() / 60) data["status"] = True data["waiting_time"] = waiting_time @@ -38,14 +39,15 @@ def get_waiting_time(place: str, db: Session): data["next_timetable"] = "{:d}h{:02d}".format(second_timeslot[0].hour, second_timeslot[0].minute) return data elif second_timeslot and current_time <= second_timeslot[1]: - waiting_time = db.query( + last_record = db.query( models.Records.waiting_time ).filter( models.Records.place == place ).order_by( models.Records.date.desc() ).first() - if waiting_time: + if last_record: + waiting_time = last_record.waiting_time waiting_time = round(waiting_time.total_seconds() / 60) data["status"] = True data["waiting_time"] = waiting_time @@ -317,14 +319,15 @@ def get_restaurants(db: Session): restaurant["timeslot"] = "-" if restaurant["status"]: - waiting_time = db.query( - models.Records.waiting_time + last_record = db.query( + models.Records ).filter( models.Records.place == name ).order_by( models.Records.date.desc() ).first() - if waiting_time: + if last_record: + waiting_time = last_record.waiting_time restaurant["waiting_time"] = round(waiting_time.total_seconds() / 60) else: restaurant["waiting_time"] = None diff --git a/backend/main.py b/backend/main.py index aa8a6b5694f8a4839d98a97ab798769b984249c1..cddefa099390a78b7e1a48f031ac0ffd29759944 100644 --- a/backend/main.py +++ b/backend/main.py @@ -43,7 +43,7 @@ app.include_router(news.router) @app.get('/api/records', response_model=List[schemas.Record]) async def get_records(place: str, db: Session = Depends(get_db)): - return db.query(models.Records).filter(models.Records == place).order_by(models.Records.date.desc()).all() + return db.query(models.Records).filter(models.Records.place == place).order_by(models.Records.date.desc()).all() @app.post('/api/records', response_model=schemas.Record) @@ -56,7 +56,7 @@ async def stats(record: schemas.RecordBase, db: Session = Depends(get_db)): @app.delete('/api/records', response_model=None) -async def stats(id: str, db: Session = Depends(get_db)): +async def stats(id: int, db: Session = Depends(get_db)): if id == 0: db.query(models.Records).delete() else: diff --git a/frontend/src/components/WaitingTime.js b/frontend/src/components/WaitingTime.js index 360adb4431f263be37b08a7e1387e1e3642614dd..7af4d42ce100a9915adf04e972f4716e5f10141f 100644 --- a/frontend/src/components/WaitingTime.js +++ b/frontend/src/components/WaitingTime.js @@ -17,7 +17,7 @@ export default function WaitingTime({ place }) { return ( <div id="waiting-time-parent"> {data.status ? ( - data.waiting_time ? ( + data.waiting_time || data.waiting_time == 0 ? ( <div id="waiting-time-display"> Le temps d'attente est estimé à <div className="waiting-time-minutes">