Initial commit - MIDAS App educação financeira para apostadores (FastAPI + Next.js)
This commit is contained in:
28
backend/app/routers/alerts.py
Normal file
28
backend/app/routers/alerts.py
Normal file
@@ -0,0 +1,28 @@
|
||||
from fastapi import APIRouter, Depends
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from sqlalchemy import select, desc
|
||||
from app.database import get_db
|
||||
from app.models.user import User
|
||||
from app.models.alert import Alert
|
||||
from app.utils.auth import get_current_user
|
||||
from app.services.risk_engine import calculate_risk_score
|
||||
|
||||
router = APIRouter(prefix="/api/alerts", tags=["alerts"])
|
||||
|
||||
@router.get("")
|
||||
async def get_alerts(user: User = Depends(get_current_user), db: AsyncSession = Depends(get_db)):
|
||||
risk = await calculate_risk_score(user.id, db)
|
||||
|
||||
# Get stored alerts
|
||||
alerts = (await db.execute(
|
||||
select(Alert).where(Alert.user_id == user.id).order_by(desc(Alert.created_at)).limit(20)
|
||||
)).scalars().all()
|
||||
|
||||
return {
|
||||
"current_risk": risk,
|
||||
"alerts": [
|
||||
{"id": str(a.id), "type": a.type, "severity": a.severity,
|
||||
"message": a.message, "is_read": a.is_read, "created_at": a.created_at.isoformat()}
|
||||
for a in alerts
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user