add 历史记录API

This commit is contained in:
jxxghp
2023-06-19 17:21:09 +08:00
parent c7f897fdcd
commit 686c0dec05
6 changed files with 109 additions and 3 deletions

View File

@ -1,6 +1,7 @@
from fastapi import APIRouter
from app.api.endpoints import login, user, site, message, webhook, subscribe, media, douban, search, plugin, tmdb
from app.api.endpoints import login, user, site, message, webhook, subscribe, \
media, douban, search, plugin, tmdb, history
api_router = APIRouter()
api_router.include_router(login.router, tags=["login"])
@ -14,3 +15,5 @@ api_router.include_router(search.router, prefix="/search", tags=["search"])
api_router.include_router(douban.router, prefix="/douban", tags=["douban"])
api_router.include_router(tmdb.router, prefix="/tmdb", tags=["tmdb"])
api_router.include_router(plugin.router, prefix="/plugin", tags=["plugin"])
api_router.include_router(history.router, prefix="/history", tags=["history"])
api_router.include_router(plugin.router, prefix="/plugin", tags=["plugin"])

View File

@ -0,0 +1,39 @@
from typing import List, Any
from fastapi import APIRouter, Depends
from sqlalchemy.orm import Session
from app import schemas
from app.db import get_db
from app.db.models.downloadhistory import DownloadHistory
from app.db.models.transferhistory import TransferHistory
from app.db.models.user import User
from app.db.userauth import get_current_active_user
router = APIRouter()
@router.get("/download", summary="下载历史记录", response_model=List[schemas.Context])
async def download_history(page: int = 1,
count: int = 30,
db: Session = Depends(get_db),
_: User = Depends(get_current_active_user)) -> Any:
"""
查询下载历史记录
"""
return DownloadHistory.list_by_page(db, page, count)
@router.get("/transfer", summary="转移历史记录", response_model=List[schemas.TorrentInfo])
async def transfer_history(title: str = None,
page: int = 1,
count: int = 30,
db: Session = Depends(get_db),
_: User = Depends(get_current_active_user)) -> Any:
"""
查询转移历史记录
"""
if title:
return TransferHistory.list_by_title(db, title, page, count)
else:
return TransferHistory.list_by_page(db, page, count)