diff --git a/backend/db/crud.py b/backend/db/crud.py index a78139b403d3c246eaf9d2ed95443c5e9a4bc016..246b0f692a1fb2921da42ec12d37eb89659f5e64 100644 --- a/backend/db/crud.py +++ b/backend/db/crud.py @@ -183,7 +183,18 @@ def get_comments(place: str, page: int, db: Session): if page == 0: comments = db.query(models.Comments).order_by(models.Comments.published_at.desc(), models.Comments.id.desc()).all() else: - comments = db.query(models.Comments, models.Users.username).join(models.Users).filter(models.Comments.place == place).order_by(models.Comments.published_at.desc(), models.Comments.id.desc()).slice((page - 1) * 20, page * 20).all() + comments = db.query( + models.Comments, + models.Users.username).join( + models.Users).filter( + models.Comments.place == place).order_by( + models.Comments.published_at.desc(), + models.Comments.id.desc()).slice( + (page - + 1) * + 20, + page * + 20).all() return list(schemas.Comment(**comment.__dict__, username=username) for comment, username in comments) @@ -369,14 +380,14 @@ def update_user(user: schemas.User, user_info: dict, db: Session): existing_user.cookie = user.cookie existing_user.expiration_date = expiration_date db.delete(user) - db.add(existing_user) + db.add(existing_user) db.commit() db.refresh(existing_user) return existing_user else: user.username = full_name user.expiration_date = expiration_date - db.add(user) + db.add(user) db.commit() db.refresh(user) return user @@ -387,4 +398,4 @@ def end_session(cookie: str, db: Session): user.expiration_date = datetime.now(tz=pytz.timezone("Europe/Paris")) db.add(user) db.commit() - return \ No newline at end of file + return diff --git a/backend/db/models.py b/backend/db/models.py index 13ea196e0774db64836cfbae2b3a5411ddb20264..ff985da4d23f28c5b5868fb0bd7ded7aedcb53dc 100644 --- a/backend/db/models.py +++ b/backend/db/models.py @@ -62,4 +62,4 @@ class Users(Base): username = Column(String(50)) cookie = Column(String(50)) expiration_date = Column(DateTime) - comments = relationship("Comments") \ No newline at end of file + comments = relationship("Comments") diff --git a/backend/db/schemas.py b/backend/db/schemas.py index 86bb23b204cc22cb38fc95bc8344fdc0ae72ff3b..55e13ba87afc25f6a8e75611a18f6def36ab9e81 100644 --- a/backend/db/schemas.py +++ b/backend/db/schemas.py @@ -30,7 +30,7 @@ class CommentBase(BaseModel): class Comment(CommentBase): """Comments reading schema""" id: int - username : str = Field(..., title="Name of the user posting the comment") + username: str = Field(..., title="Name of the user posting the comment") published_at: datetime = Field(..., title="Publication date of the comment") place: str = Field(..., title="Name of the RU corresponding the comment") @@ -78,4 +78,4 @@ class User(BaseModel): state: str username: str cookie: str - expiration_date: datetime \ No newline at end of file + expiration_date: datetime diff --git a/backend/routers/__init__.py b/backend/routers/__init__.py index 92c71e361349ea060f8bf331df5f9155acd4706e..b751487ca496e209213000e5a5d9e49653cafcbb 100644 --- a/backend/routers/__init__.py +++ b/backend/routers/__init__.py @@ -2,4 +2,4 @@ from . import authentication from . import comments from . import news from . import opening_hours -from . import stats \ No newline at end of file +from . import stats diff --git a/backend/routers/authentication.py b/backend/routers/authentication.py index 856493d678e286666dd13f978069da25310a40e1..df409dfcfe6f9caa9e336ae1a0dea47744f67f4f 100644 --- a/backend/routers/authentication.py +++ b/backend/routers/authentication.py @@ -54,7 +54,7 @@ async def login(code: Optional[str] = None, state: Optional[str] = None, connect "client_id": os.getenv("CLIENT_ID"), "client_secret": os.getenv("CLIENT_SECRET"), } - + token_response = post( f"{os.getenv('AUTH_ROOT')}/oauth/token", data=data, @@ -76,4 +76,4 @@ async def delete_session(connect_id: str = Cookie(...), db: Session = Depends(ge response = RedirectResponse(f"{os.getenv('AUTH_ROOT')}/logout?{urlencode({'redirect_logout': os.getenv('WEB_ROOT')})}") response.delete_cookie(key="connect_id") crud.end_session(connect_id, db) - return response \ No newline at end of file + return response diff --git a/frontend/src/components/Comments.js b/frontend/src/components/Comments.js index 2b93bcf04f8db3b753cee4c1fb3904a4058ec2d1..a195b65141808f36184612b33dde3fe87e4cfd2e 100644 --- a/frontend/src/components/Comments.js +++ b/frontend/src/components/Comments.js @@ -152,7 +152,9 @@ export default function Messages({ place, infos }) { let [year, month, day] = date.split("-"); return ( <div key={index} className="comment"> - <div className={`comment-title${infos ? "-infos" : ""}`}>{infos ? message.title : message.username}</div> + <div className={`comment-title${infos ? "-infos" : ""}`}> + {infos ? message.title : message.username} + </div> <div className="comment-content">{message.content}</div> <div className="comment-date"> {`À ${hour.substring(0, 5)} le ${day}/${month}/${year}`}