diff --git a/backend/db/crud.py b/backend/db/crud.py index c460f2edf4309b7d365238419bbb5c5b83fc522a..6315054655b56f50af8d58009d7c874dd7f8a7d3 100644 --- a/backend/db/crud.py +++ b/backend/db/crud.py @@ -9,7 +9,7 @@ import pytz from db import models, schemas -## Define CRUD operation to collect the statistics +# Define CRUD operation to collect the statistics def get_waiting_time(place: str, db: Session): """ Get the last estimated waiting time for the given place """ @@ -61,14 +61,23 @@ def get_stats(place: str, weekday: int, min_time_hour: int, min_time_mn: int, ma return stats -## Define CRUD operation for the comments +# Define CRUD operation for the comments def get_comments(place: str, page: int, db: Session): """ Get the 10 last comments for the given place """ if page == 0: comments = db.query(models.Comments).order_by(models.Comments.date.desc(), models.Comments.id.desc()).all() else: - comments = db.query(models.Comments).filter(models.Comments.place == place).order_by(models.Comments.date.desc(), models.Comments.id.desc()).slice((page-1)*10, page*10).all() + comments = db.query( + models.Comments).filter( + models.Comments.place == place).order_by( + models.Comments.date.desc(), + models.Comments.id.desc()).slice( + (page - + 1) * + 10, + page * + 10).all() return comments @@ -91,7 +100,7 @@ def delete_comment(id: int, db: Session): db.commit() -## Define CRUD operation for the news +# Define CRUD operation for the news def get_news(place: str, db: Session): """ Get the news for the given place """ @@ -115,4 +124,4 @@ def delete_news(id: int, db: Session): db.query(models.News).delete() else: db.query(models.News).filter(models.News.id == id).delete() - db.commit() \ No newline at end of file + db.commit() diff --git a/backend/db/database.py b/backend/db/database.py index eed306e1c7a5c376610797cd336f263c9d268ba3..0a83d518ebd24cab45dc89fe6263c1cf5d47d798 100644 --- a/backend/db/database.py +++ b/backend/db/database.py @@ -22,10 +22,11 @@ SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine) Base = declarative_base() + def get_db(): """Create a database session.""" db = SessionLocal() try: yield db finally: - db.close() \ No newline at end of file + db.close() diff --git a/backend/db/schemas.py b/backend/db/schemas.py index edb7b333076dfcd82983406143c84a372752f385..71fe821a3c09d88cbdee83cfc214945fcc3518fd 100644 --- a/backend/db/schemas.py +++ b/backend/db/schemas.py @@ -51,4 +51,4 @@ class News(NewsBase): published_at: datetime = Field(..., title="Publication date of the news") class Config: - orm_mode = True \ No newline at end of file + orm_mode = True diff --git a/backend/docker-compose.yml b/backend/docker-compose.yml index 1ee257b2850fa504d09ba2bd1e520c12c8c98faf..4cb18fd166c09899ed5bc8cd0844b14d82b148fd 100644 --- a/backend/docker-compose.yml +++ b/backend/docker-compose.yml @@ -17,20 +17,20 @@ services: volumes: - mysql-db:/var/lib/mysql - app: - build: . - container_name: "app" - depends_on: - db: - condition: service_healthy - restart: always - ports: - - 8000:80 - env_file: .env - environment: - DB_HOST: db - links: - - db + # app: + # build: . + # container_name: "app" + # depends_on: + # db: + # condition: service_healthy + # restart: always + # ports: + # - 8000:80 + # env_file: .env + # environment: + # DB_HOST: db + # links: + # - db volumes: mysql-db: \ No newline at end of file diff --git a/backend/main.py b/backend/main.py index 21db8ec7c9ec9137f1526ae66cacd41b100096f1..d4d2ed49d8b5d2e69c4a45a7bcc8b1006f389a8b 100644 --- a/backend/main.py +++ b/backend/main.py @@ -36,9 +36,6 @@ app.include_router(comments.router) app.include_router(news.router) - - - """ import cv2 import numpy as np diff --git a/backend/routers/comments.py b/backend/routers/comments.py index ee7ce9d6368179fb9b58dda41f63a3ecb5601bbe..0e44fbdd2307fd2ae3fa1554693f66b87b6476fe 100644 --- a/backend/routers/comments.py +++ b/backend/routers/comments.py @@ -10,7 +10,7 @@ router = APIRouter(prefix="/api/comments", tags=["comments"]) @router.get('/{place}', response_model=List[schemas.Comment]) -async def get_comments(place: str, page: int=1, db: Session = Depends(get_db)): +async def get_comments(place: str, page: int = 1, db: Session = Depends(get_db)): return crud.get_comments(place, page, db) @@ -21,4 +21,4 @@ async def create_comment(place: str, comment: schemas.CommentBase, db: Session = @router.delete('/{id}', response_model=None) async def delete_comment(id: int, db: Session = Depends(get_db)): - return crud.delete_comment(id, db) \ No newline at end of file + return crud.delete_comment(id, db) diff --git a/backend/routers/news.py b/backend/routers/news.py index 4d0bd3e27d38a1dfb54465e8512d97e0734986f7..8e8ecfb3d378c544ca009ade182954dd65a41dbd 100644 --- a/backend/routers/news.py +++ b/backend/routers/news.py @@ -21,4 +21,4 @@ async def create_news(place: str, news: schemas.NewsBase, db: Session = Depends( @router.delete('/{id}', response_model=None) async def delete_news(id: int, db: Session = Depends(get_db)): - return crud.delete_news(id, db) \ No newline at end of file + return crud.delete_news(id, db) diff --git a/backend/routers/stats.py b/backend/routers/stats.py index 69bc3375d5280b6e0cc5aa8191cf2f9f63677127..092a062ed141b9841051e9d7d5b28e81e96a375a 100644 --- a/backend/routers/stats.py +++ b/backend/routers/stats.py @@ -18,4 +18,4 @@ async def waiting_time(place: str, db: Session = Depends(get_db)): @router.get('/{place}/stats/{day}/{min_time_hour}/{min_time_mn}/{max_time_hour}/{max_time_mn}/{interval}', response_model=list) async def stats(place: str, day: int, min_time_hour: int, min_time_mn: int, max_time_hour: int, max_time_mn: int, interval: timedelta, db: Session = Depends(get_db)): - return crud.get_stats(place, day, min_time_hour, min_time_mn, max_time_hour, max_time_mn, interval, db) \ No newline at end of file + return crud.get_stats(place, day, min_time_hour, min_time_mn, max_time_hour, max_time_mn, interval, db)