查询接口修改
This commit is contained in:
@@ -28,16 +28,23 @@ def get_accounts(request: AccountListRequest, db: Session = Depends(get_db)):
|
||||
"""获取账号列表"""
|
||||
return AccountService.get_accounts(db, skip=request.skip, limit=request.limit)
|
||||
|
||||
@router.post("/get", response_model=AccountResponse)
|
||||
@router.post("/get", response_model=List[AccountResponse])
|
||||
def get_account(request: AccountGetRequest, db: Session = Depends(get_db)):
|
||||
"""根据ID获取账号"""
|
||||
account = AccountService.get_account(db, request.account_id)
|
||||
if not account:
|
||||
"""根据多种条件查询账号"""
|
||||
accounts = AccountService.search_accounts(
|
||||
db,
|
||||
account_id=request.account_id,
|
||||
account=request.account,
|
||||
section=request.section,
|
||||
status=request.status,
|
||||
today_updated=request.today_updated
|
||||
)
|
||||
if not accounts:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND,
|
||||
detail="账号不存在"
|
||||
detail="未找到符合条件的账号"
|
||||
)
|
||||
return account
|
||||
return accounts
|
||||
|
||||
@router.post("/update", response_model=AccountResponse)
|
||||
def update_account(request: AccountUpdateRequest, db: Session = Depends(get_db)):
|
||||
|
||||
@@ -13,6 +13,26 @@ class AccountService:
|
||||
db.refresh(db_account)
|
||||
return db_account
|
||||
|
||||
@staticmethod
|
||||
def search_accounts(db: Session, account_id: Optional[int] = None,
|
||||
account: Optional[str] = None, section: Optional[str] = None,
|
||||
status: Optional[int] = None, today_updated: Optional[int] = None) -> List[Account]:
|
||||
"""根据多种条件搜索账号"""
|
||||
query = db.query(Account)
|
||||
|
||||
if account_id is not None:
|
||||
query = query.filter(Account.id == account_id)
|
||||
if account is not None:
|
||||
query = query.filter(Account.account.like(f"%{account}%"))
|
||||
if section is not None:
|
||||
query = query.filter(Account.section.like(f"%{section}%"))
|
||||
if status is not None:
|
||||
query = query.filter(Account.status == status)
|
||||
if today_updated is not None:
|
||||
query = query.filter(Account.today_updated == today_updated)
|
||||
|
||||
return query.all()
|
||||
|
||||
@staticmethod
|
||||
def get_account(db: Session, account_id: int) -> Optional[Account]:
|
||||
"""根据ID获取账号"""
|
||||
|
||||
Reference in New Issue
Block a user