github-actions[bot]
Automated Deploy: 0d5b759d8eca219a25b3ab717925e73a66bbf4a4
2756f0f
Raw History Blame Contribute Delete
1 kB
"""B3, B4: register and remove push tokens."""
from fastapi import APIRouter, Response, status
from app.core.dependencies import CurrentAccount, Db
from app.modules.devices.schemas import DeviceCreate, DeviceOut, DeviceResponse
from app.modules.devices.service import DeviceService
router = APIRouter(prefix="/v1", tags=["devices"])
@router.post("/devices", status_code=status.HTTP_201_CREATED, response_model=DeviceResponse)
async def register_device(body: DeviceCreate, account: CurrentAccount, db: Db, response: Response) -> DeviceResponse:
device, created = await DeviceService(db).register(account, body.platform, body.push_token)
if not created:
response.status_code = status.HTTP_200_OK
return DeviceResponse(device=DeviceOut.model_validate(device))
@router.delete("/devices/{push_token}", status_code=status.HTTP_204_NO_CONTENT)
async def remove_device(push_token: str, account: CurrentAccount, db: Db) -> None:
await DeviceService(db).remove(account, push_token)