5d895ae12c
- Fix exchange.py: replace {'error':...} with HTTPException(detail=...)
- Fix payment/admin/teams/quotation: str(e) messages are already user-safe
- Confirm admin_search.py test endpoint uses correct probe pattern
- Confirm frontend has no raw alert() calls (already uses ElMessage)
37 lines
1012 B
Python
37 lines
1012 B
Python
from fastapi import APIRouter, HTTPException
|
|
from app.services.exchange import ExchangeRateService
|
|
from datetime import datetime
|
|
|
|
router = APIRouter()
|
|
service = ExchangeRateService()
|
|
|
|
|
|
@router.get("/convert")
|
|
async def convert_currency(
|
|
from_currency: str = "USD",
|
|
to_currency: str = "CNY",
|
|
amount: float = 1.0,
|
|
):
|
|
rate = await service.get_rate(from_currency, to_currency)
|
|
if rate is None:
|
|
raise HTTPException(status_code=404, detail=f"汇率不可用: {from_currency} → {to_currency}")
|
|
|
|
return {
|
|
"from_currency": from_currency.upper(),
|
|
"to_currency": to_currency.upper(),
|
|
"amount": amount,
|
|
"converted": round(amount * rate, 2),
|
|
"rate": rate,
|
|
"updated_at": datetime.utcnow().isoformat(),
|
|
}
|
|
|
|
|
|
@router.get("/rates")
|
|
async def get_rates(base: str = "USD"):
|
|
rates = await service.get_all_rates(base)
|
|
return {
|
|
"base": base.upper(),
|
|
"rates": rates,
|
|
"updated_at": datetime.utcnow().isoformat(),
|
|
}
|