Skip to content

Commit

Permalink
- 修复了未设置订阅站点时无法编辑订阅的问题
Browse files Browse the repository at this point in the history
- 历史记录支持过滤状态
  • Loading branch information
jxxghp committed Dec 23, 2023
1 parent 8f4f4cc commit dcf1985
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 13 deletions.
15 changes: 12 additions & 3 deletions app/api/endpoints/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,25 @@ def delete_download_history(history_in: schemas.DownloadHistory,
def transfer_history(title: str = None,
page: int = 1,
count: int = 30,
status: bool = None,
db: Session = Depends(get_db),
_: schemas.TokenPayload = Depends(verify_token)) -> Any:
"""
查询转移历史记录
"""
if title == "失败":
title = None
status = False
elif title == "成功":
title = None
status = True

if title:
total = TransferHistory.count_by_title(db, title)
result = TransferHistory.list_by_title(db, title, page, count)
total = TransferHistory.count_by_title(db, title=title, status=status)
result = TransferHistory.list_by_title(db, title=title, page=page,
count=count, status=status)
else:
result = TransferHistory.list_by_page(db, page, count)
result = TransferHistory.list_by_page(db, page=page, count=count, status=status)
total = TransferHistory.count(db)

return schemas.Response(success=True,
Expand Down
33 changes: 24 additions & 9 deletions app/db/models/transferhistory.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,28 @@ class TransferHistory(Base):

@staticmethod
@db_query
def list_by_title(db: Session, title: str, page: int = 1, count: int = 30):
result = db.query(TransferHistory).filter(TransferHistory.title.like(f'%{title}%')).order_by(
TransferHistory.date.desc()).offset((page - 1) * count).limit(
count).all()
def list_by_title(db: Session, title: str, page: int = 1, count: int = 30, status: bool = None):
if status is not None:
result = db.query(TransferHistory).filter(TransferHistory.title.like(f'%{title}%'),
TransferHistory.status == status).order_by(
TransferHistory.date.desc()).offset((page - 1) * count).limit(
count).all()
else:
result = db.query(TransferHistory).filter(TransferHistory.title.like(f'%{title}%')).order_by(
TransferHistory.date.desc()).offset((page - 1) * count).limit(
count).all()
return list(result)

@staticmethod
@db_query
def list_by_page(db: Session, page: int = 1, count: int = 30):
result = db.query(TransferHistory).order_by(TransferHistory.date.desc()).offset((page - 1) * count).limit(
count).all()
def list_by_page(db: Session, page: int = 1, count: int = 30, status: bool = None):
if status is not None:
result = db.query(TransferHistory).filter(TransferHistory.status == status).order_by(
TransferHistory.date.desc()).offset((page - 1) * count).limit(
count).all()
else:
result = db.query(TransferHistory).order_by(TransferHistory.date.desc()).offset((page - 1) * count).limit(
count).all()
return list(result)

@staticmethod
Expand Down Expand Up @@ -97,8 +108,12 @@ def count(db: Session):

@staticmethod
@db_query
def count_by_title(db: Session, title: str):
return db.query(func.count(TransferHistory.id)).filter(TransferHistory.title.like(f'%{title}%')).first()[0]
def count_by_title(db: Session, title: str, status: bool = None):
if status is not None:
return db.query(func.count(TransferHistory.id)).filter(TransferHistory.title.like(f'%{title}%'),
TransferHistory.status == status).first()[0]
else:
return db.query(func.count(TransferHistory.id)).filter(TransferHistory.title.like(f'%{title}%')).first()[0]

@staticmethod
@db_query
Expand Down
2 changes: 1 addition & 1 deletion version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
APP_VERSION = 'v1.5.3'
APP_VERSION = 'v1.5.4'

0 comments on commit dcf1985

Please sign in to comment.