first commit
This commit is contained in:
36
backend/app/api/v1/transactions.py
Normal file
36
backend/app/api/v1/transactions.py
Normal file
@@ -0,0 +1,36 @@
|
||||
from uuid import UUID
|
||||
|
||||
from fastapi import APIRouter, Depends, Query, HTTPException
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.core.database import get_db
|
||||
from app.repositories.transaction_repo import TransactionRepository
|
||||
from app.schemas.transaction import TransactionOut, TransactionListOut, FlowGraphOut
|
||||
from app.services.flow_service import build_flow_graph
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.get("/cases/{case_id}/transactions", response_model=TransactionListOut)
|
||||
async def list_transactions(
|
||||
case_id: UUID,
|
||||
filter_type: str | None = Query(None, description="all / unique / duplicate"),
|
||||
db: AsyncSession = Depends(get_db),
|
||||
):
|
||||
repo = TransactionRepository(db)
|
||||
items, total = await repo.list_by_case(case_id, filter_type=filter_type)
|
||||
return TransactionListOut(items=items, total=total)
|
||||
|
||||
|
||||
@router.get("/transactions/{tx_id}", response_model=TransactionOut)
|
||||
async def get_transaction(tx_id: UUID, db: AsyncSession = Depends(get_db)):
|
||||
repo = TransactionRepository(db)
|
||||
tx = await repo.get(tx_id)
|
||||
if not tx:
|
||||
raise HTTPException(404, "交易不存在")
|
||||
return tx
|
||||
|
||||
|
||||
@router.get("/cases/{case_id}/flows", response_model=FlowGraphOut)
|
||||
async def get_fund_flows(case_id: UUID, db: AsyncSession = Depends(get_db)):
|
||||
return await build_flow_graph(case_id, db)
|
||||
Reference in New Issue
Block a user