Files
TradeMate Dev 5d895ae12c fix: standardize error response format
- 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)
2026-06-11 19:38:05 +08:00

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(),
}