From bd729feb669b61847223b0754fd0f981e852d8c8 Mon Sep 17 00:00:00 2001 From: jxxghp Date: Mon, 17 Jul 2023 08:40:40 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E5=8E=86=E5=8F=B2=E8=AE=B0=E5=BD=95?= =?UTF-8?q?=E7=BF=BB=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/endpoints/history.py | 23 +++++++++++++---------- app/db/models/transferhistory.py | 4 ++-- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/app/api/endpoints/history.py b/app/api/endpoints/history.py index 219e5b8d..f12fe5e7 100644 --- a/app/api/endpoints/history.py +++ b/app/api/endpoints/history.py @@ -40,23 +40,26 @@ def delete_download_history(history_in: schemas.DownloadHistory, def transfer_history(title: str = None, page: int = 1, count: int = 30, + sort: dict = None, db: Session = Depends(get_db), _: schemas.TokenPayload = Depends(verify_token)) -> Any: """ 查询转移历史记录 """ if title: - return schemas.Response(success=True, - data={ - "list": TransferHistory.list_by_title(db, title, page, count), - "total": TransferHistory.count_by_title(db, title), - }) + total = TransferHistory.count_by_title(db, title) + result = TransferHistory.list_by_title(db, title, page, count) else: - return schemas.Response(success=True, - data={ - "list": TransferHistory.list_by_page(db, page, count), - "total": TransferHistory.count(db), - }) + result = TransferHistory.list_by_page(db, page, count) + total = TransferHistory.count(db) + # 排序 + if sort: + pass + return schemas.Response(success=True, + data={ + "list": result, + "total": total, + }) @router.delete("/transfer", summary="删除转移历史记录", response_model=schemas.Response) diff --git a/app/db/models/transferhistory.py b/app/db/models/transferhistory.py index 26064dfe..d5991375 100644 --- a/app/db/models/transferhistory.py +++ b/app/db/models/transferhistory.py @@ -46,7 +46,7 @@ class TransferHistory(Base): @staticmethod def list_by_title(db: Session, title: str, page: int = 1, count: int = 30): - return db.query(TransferHistory).filter(TransferHistory.title == title).order_by( + return db.query(TransferHistory).filter(TransferHistory.title.like(f'%{title}%')).order_by( TransferHistory.date.desc()).offset((page - 1) * count).limit( count).all() @@ -76,4 +76,4 @@ class TransferHistory(Base): @staticmethod def count_by_title(db: Session, title: str): - return db.query(func.count(TransferHistory.id)).filter(TransferHistory.title == title).first()[0] + return db.query(func.count(TransferHistory.id)).filter(TransferHistory.title.like(f'%{title}%')).first()[0]