Backend: - app/models/email_log.py: EmailLog table (school_id, to, subject, type, status, error, sent_at) with EmailType + EmailStatus enums - migrations/002_phase9_email_logs.py: Alembic migration for email_logs table - app/templates/email/: 6 Jinja2 HTML templates — base layout, invoice, low_credit, license_expiry, overdue_warning, suspension - app/services/email.py: enhanced send_email() — accepts template_name+context for HTML rendering, logs every attempt to email_logs, retries up to 3x on transient SMTP failure with exponential backoff - app/routers/email.py: GET /api/email/logs (paginated, filterable by type/status/school), POST /api/email/test (send test email, super admin) - tasks/billing.py: invoice + overdue warning + suspension emails now use HTML templates - tasks/sms.py: low credit alert now uses HTML template - tasks/license.py: expiry warning now uses HTML template - app/main.py + migrations/env.py: wire in email_log model + email router Frontend: - EmailLogsPage.vue: table with to/subject/type badge/status badge/sent_at/error, type+status filters, pagination, Send Test Email modal - router/index.ts: /email-logs route - AppSidebar.vue: Email Logs nav item - api.ts: getEmailLogs, sendTestEmail
52 lines
1.6 KiB
Python
52 lines
1.6 KiB
Python
"""TapTrack Hub — FastAPI application entry point."""
|
|
from contextlib import asynccontextmanager
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
from app.database import engine, Base
|
|
# Import all models so Alembic/SQLAlchemy picks them up
|
|
from app.models import user, school, license, sms, billing, ticket, audit, announcement, email_log # noqa
|
|
|
|
from app.routers import auth, schools, licenses, sms as sms_router, billing as billing_router
|
|
from app.routers import tickets, users, dashboard, school_portal, announcements, sync, email as email_router
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI):
|
|
# Create tables if not exists (dev convenience — use Alembic in prod)
|
|
async with engine.begin() as conn:
|
|
await conn.run_sync(Base.metadata.create_all)
|
|
yield
|
|
|
|
app = FastAPI(
|
|
title="TapTrack Hub",
|
|
description="Cloud control plane for TapTrack on-prem deployments",
|
|
version="1.0.0",
|
|
lifespan=lifespan,
|
|
)
|
|
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["*"],
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
# Routers
|
|
app.include_router(auth.router)
|
|
app.include_router(schools.router)
|
|
app.include_router(licenses.router)
|
|
app.include_router(sms_router.router)
|
|
app.include_router(billing_router.router)
|
|
app.include_router(tickets.router)
|
|
app.include_router(users.router)
|
|
app.include_router(dashboard.router)
|
|
app.include_router(school_portal.router)
|
|
app.include_router(announcements.router)
|
|
app.include_router(sync.router)
|
|
app.include_router(email_router.router)
|
|
|
|
@app.get("/api/health")
|
|
async def health():
|
|
return {"status": "ok", "service": "taptrack-hub"}
|