diff options
| author | Christian Cleberg <[email protected]> | 2026-04-08 14:29:21 -0500 |
|---|---|---|
| committer | Christian Cleberg <[email protected]> | 2026-04-08 14:29:21 -0500 |
| commit | a7c25076d16bde9ec928b9ef01bce952406ea7b1 (patch) | |
| tree | 802c5f84902f240c6aab95acc1e6348dfbd806c2 /app/routers/test.py | |
| download | hutch-notify-a7c25076d16bde9ec928b9ef01bce952406ea7b1.tar.gz hutch-notify-a7c25076d16bde9ec928b9ef01bce952406ea7b1.tar.bz2 hutch-notify-a7c25076d16bde9ec928b9ef01bce952406ea7b1.zip | |
initial commit
Diffstat (limited to 'app/routers/test.py')
| -rw-r--r-- | app/routers/test.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/app/routers/test.py b/app/routers/test.py new file mode 100644 index 0000000..70a5d4e --- /dev/null +++ b/app/routers/test.py @@ -0,0 +1,33 @@ +from fastapi import APIRouter, Depends, HTTPException +from sqlalchemy import select +from sqlalchemy.ext.asyncio import AsyncSession + +from app.apns import APNSClient +from app.db import get_db +from app.models import Device +from app.security import require_api_key + +router = APIRouter(prefix="/v1/test", tags=["test"], dependencies=[Depends(require_api_key)]) + + [email protected]("/push/{device_id}") +async def test_push(device_id: int, db: AsyncSession = Depends(get_db)) -> dict: + result = await db.execute(select(Device).where(Device.id == device_id)) + device = result.scalar_one_or_none() + if device is None: + raise HTTPException(status_code=404, detail="device not found") + + client = APNSClient() + try: + ok, apns_id, error = await client.send_alert( + device_token=device.apns_token, + apns_env=device.apns_env, + topic=device.bundle_id, + title="Hutch test", + body="Test push from hutch-notify", + payload={"event_type": "test", "deep_link": "hutch://home"}, + ) + finally: + await client.aclose() + + return {"ok": ok, "apns_id": apns_id, "error": error} |
