From 16f1e3cde83c3ad123f1eea893460a484a15c4a5 Mon Sep 17 00:00:00 2001
From: Antoine Gaudron-desjardins <antoine.gaudrondesjardins@student-cs.fr>
Date: Tue, 12 Jul 2022 15:13:17 +0200
Subject: [PATCH] fix

---
 backend/db/crud.py                     | 17 ++++++++++-------
 backend/main.py                        |  4 ++--
 frontend/src/components/WaitingTime.js |  2 +-
 3 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/backend/db/crud.py b/backend/db/crud.py
index d855220..77f677b 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 aa8a6b5..cddefa0 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 360adb4..7af4d42 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&apos;attente est estimé à
             <div className="waiting-time-minutes">
-- 
GitLab