← full-stack-fastapi-template / backend/app/api/routes/utils.py
| 1 | from fastapi import APIRouter, Depends |
| 2 | from pydantic.networks import EmailStr |
| 3 | |
| 4 | from app.api.deps import get_current_active_superuser |
| 5 | from app.models import Message |
| 6 | from app.utils import generate_test_email, send_email |
| 7 | |
| 8 | router = APIRouter(prefix="/utils", tags=["utils"]) |
| 9 | |
| 10 | |
| 11 | @router.post( |
| 12 | "/test-email/", |
| 13 | dependencies=[Depends(get_current_active_superuser)], |
| 14 | status_code=201, |
| 15 | ) |
| 16 | def test_email(email_to: EmailStr) -> Message: |
| 17 | """ |
| 18 | Test emails. |
| 19 | """ |
| 20 | email_data = generate_test_email(email_to=email_to) |
| 21 | send_email( |
| 22 | email_to=email_to, |
| 23 | subject=email_data.subject, |
| 24 | html_content=email_data.html_content, |
| 25 | ) |
| 26 | return Message(message="Test email sent") |
| 27 | |
| 28 | |
| 29 | @router.get("/health-check/") |
| 30 | async def health_check() -> bool: |
| 31 | return True |
| 32 |