fix 历史记录翻页

This commit is contained in:
jxxghp 2023-07-17 08:40:40 +08:00
parent 579d7f0574
commit bd729feb66
2 changed files with 15 additions and 12 deletions

View File

@ -40,23 +40,26 @@ def delete_download_history(history_in: schemas.DownloadHistory,
def transfer_history(title: str = None, def transfer_history(title: str = None,
page: int = 1, page: int = 1,
count: int = 30, count: int = 30,
sort: dict = None,
db: Session = Depends(get_db), db: Session = Depends(get_db),
_: schemas.TokenPayload = Depends(verify_token)) -> Any: _: schemas.TokenPayload = Depends(verify_token)) -> Any:
""" """
查询转移历史记录 查询转移历史记录
""" """
if title: if title:
return schemas.Response(success=True, total = TransferHistory.count_by_title(db, title)
data={ result = TransferHistory.list_by_title(db, title, page, count)
"list": TransferHistory.list_by_title(db, title, page, count),
"total": TransferHistory.count_by_title(db, title),
})
else: else:
return schemas.Response(success=True, result = TransferHistory.list_by_page(db, page, count)
data={ total = TransferHistory.count(db)
"list": 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) @router.delete("/transfer", summary="删除转移历史记录", response_model=schemas.Response)

View File

@ -46,7 +46,7 @@ class TransferHistory(Base):
@staticmethod @staticmethod
def list_by_title(db: Session, title: str, page: int = 1, count: int = 30): 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( TransferHistory.date.desc()).offset((page - 1) * count).limit(
count).all() count).all()
@ -76,4 +76,4 @@ class TransferHistory(Base):
@staticmethod @staticmethod
def count_by_title(db: Session, title: str): 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]