- api/: FastAPI app with MySQL (accounts, forwarding_rules, messages)
- GET/POST/PUT/DELETE /accounts + /accounts/{id}/test
- GET /messages + /messages/{id}/retry
- GET /stats
- POST /connection/test
- Auto-runs migrations/init.sql on startup
- worker/: Python IMAP poller + BizDocs upload (schedule every 5 min)
- web/: multi-stage Dockerfile — builds admin-ui via Node, serves via nginx
- nginx proxies /api/ → api:8000, SPA fallback for React Router
- docker-compose.yml: updated web build context + mysql init.sql mount
Co-Authored-By: Paperclip <[email protected]>
35 lines
1.3 KiB
Python
35 lines
1.3 KiB
Python
from fastapi import APIRouter, Depends
|
|
from sqlalchemy import func, select
|
|
from sqlalchemy.orm import Session
|
|
|
|
from ..database import get_db
|
|
from ..models import Account, Message
|
|
from ..schemas import StatsOut
|
|
|
|
router = APIRouter(tags=["stats"])
|
|
|
|
|
|
@router.get("/stats", response_model=StatsOut)
|
|
def get_stats(db: Session = Depends(get_db)):
|
|
accounts_total = db.query(func.count(Account.id)).scalar() or 0
|
|
accounts_active = db.query(func.count(Account.id)).filter(Account.active == True).scalar() or 0
|
|
|
|
messages_total = db.query(func.count(Message.id)).scalar() or 0
|
|
messages_pending = db.query(func.count(Message.id)).filter(Message.status == "pending").scalar() or 0
|
|
messages_forwarded = db.query(func.count(Message.id)).filter(Message.status == "forwarded").scalar() or 0
|
|
messages_failed = db.query(func.count(Message.id)).filter(Message.status == "failed").scalar() or 0
|
|
|
|
last_sync = (
|
|
db.query(func.max(Account.last_checked_at)).scalar()
|
|
)
|
|
|
|
return StatsOut(
|
|
accounts_total=accounts_total,
|
|
accounts_active=accounts_active,
|
|
messages_total=messages_total,
|
|
messages_pending=messages_pending,
|
|
messages_forwarded=messages_forwarded,
|
|
messages_failed=messages_failed,
|
|
last_sync_at=last_sync,
|
|
)
|