From 6214bb0f0749fa0a54e7cecb27cfd24a199b6800 Mon Sep 17 00:00:00 2001 From: Administrator Date: Tue, 11 Jul 2023 17:06:49 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=84=E8=AE=BA=E7=9A=84=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E5=9B=9E=E9=80=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Mods/Comment/Crud.py | 6 +++--- Mods/Comment/Models.py | 6 +----- Mods/Comment/Router.py | 2 +- Mods/Comment/Schemas.py | 2 -- Utils/SqlAlchemyUtils.py | 2 +- 5 files changed, 6 insertions(+), 12 deletions(-) diff --git a/Mods/Comment/Crud.py b/Mods/Comment/Crud.py index aa85b3c..8d634a8 100644 --- a/Mods/Comment/Crud.py +++ b/Mods/Comment/Crud.py @@ -34,9 +34,9 @@ def comment_query(db: Session, params: Schemas.CommentQuery): db_model = Comment for key, value in params_dict.items(): if key not in ['page', 'page_size'] and value is not None: - if key in ['user_email', 'receiver_user_email']: - query = query.filter(getattr(db_model, key) == value) - continue + # if key in ['user_email', 'receiver_user_email']: + # query = query.filter(getattr(db_model, key) == value) + # continue if type(value) == str: query = query.filter(getattr(db_model, key).like(f'%{value}%')) elif type(value) in [int, float, bool]: diff --git a/Mods/Comment/Models.py b/Mods/Comment/Models.py index d80668a..afd1da9 100644 --- a/Mods/Comment/Models.py +++ b/Mods/Comment/Models.py @@ -15,9 +15,7 @@ class Comment(Base): daily_id = Column(Integer, ForeignKey('daily.id', ondelete='CASCADE')) daily = relationship('Daily', back_populates='comments') user_email = Column(String(255), ForeignKey('user.email', ondelete='CASCADE')) - receiver_user_email = Column(String(255), ForeignKey('user.email', ondelete='CASCADE')) - user = relationship('User', backref='self_comments', foreign_keys=[user_email]) - receiver_user = relationship('User', backref='receiver_comments', foreign_keys=[receiver_user_email]) + user = relationship('User', backref='comments') create_time = Column(DateTime, server_default=func.now(), comment='创建时间') def to_dict(self, full=False): @@ -37,6 +35,4 @@ class Comment(Base): data[c.name] = getattr(self, c.name) if self.user: data['user'] = self.user.to_dict() - if self.receiver_user: - data['receiver_user'] = self.receiver_user.to_dict() return data diff --git a/Mods/Comment/Router.py b/Mods/Comment/Router.py index fc25ae6..2ae4388 100644 --- a/Mods/Comment/Router.py +++ b/Mods/Comment/Router.py @@ -53,7 +53,7 @@ def comment_get(req: Schemas.CommentGetReq, db: Session = Depends(get_db)): @router.post("/comment/query", summary="查询评论", response_model=Schemas.CommentQueryRes) def comment_query(req: Schemas.CommentQueryReq, db: Session = Depends(get_db)): count, query = Crud.comment_query(db, req) - items = [Schemas.CommentInfo(**item.to_with_user_dict()) for item in query] + items = [Schemas.CommentInfo(**item.to_dict()) for item in query] return Schemas.CommentQueryRes(count=count, items=items) diff --git a/Mods/Comment/Schemas.py b/Mods/Comment/Schemas.py index 9ccafb3..f07c285 100644 --- a/Mods/Comment/Schemas.py +++ b/Mods/Comment/Schemas.py @@ -9,12 +9,10 @@ class CommentInfo(BaseModel): id: Optional[int] daily_id: Optional[int] user_email: Optional[str] - receiver_user_email: Optional[str] daily: Optional[DailyInfo] content: Optional[str] user: Optional[UserInfo] create_time: Optional[datetime] - receiver_user: Optional[UserInfo] class CommentAddInfo(BaseModel): diff --git a/Utils/SqlAlchemyUtils.py b/Utils/SqlAlchemyUtils.py index 2b7bb4b..62011a2 100644 --- a/Utils/SqlAlchemyUtils.py +++ b/Utils/SqlAlchemyUtils.py @@ -9,7 +9,7 @@ from typing import Literal, List, Any, Optional Base = declarative_base() user = "root" -password = "12345" +password = "123456" host = "127.0.0.1" db = 'daily'