feat(): register device route

This commit is contained in:
gitgernit
2025-11-21 00:18:55 +03:00
parent 301ea62557
commit 2e073146bf
11 changed files with 88 additions and 9 deletions
@@ -2,7 +2,10 @@ from dishka import BaseScope, Provider, Scope, provide_all
from template_project.application.auth_identity.interactors.sign_in import SignInInteractor
from template_project.application.auth_identity.interactors.sign_up import SignUpInteractor
from template_project.application.user.notification.interactors.send_notification import NotificationInteractor
from template_project.application.notification_device.interactors.register_device import (
RegisterNotificationDeviceInteractor,
)
from template_project.application.notification_device.interactors.send_notification import NotificationInteractor
from template_project.application.user.profile.interactors.get_profile import GetProfileInteractor
from template_project.application.user.profile.interactors.patch_profile import PatchProfileInteractor
@@ -16,4 +19,5 @@ class InteractorProvider(Provider):
GetProfileInteractor,
PatchProfileInteractor,
NotificationInteractor,
RegisterNotificationDeviceInteractor,
)
@@ -4,11 +4,15 @@ from fastapi import APIRouter, Depends, HTTPException, status
from fastapi.security import HTTPBearer
from pydantic import BaseModel
from template_project.application.user.notification.interactors.send_notification import (
from template_project.application.notification_device.errors import NotificationDeviceNotFoundError
from template_project.application.notification_device.interactors.register_device import (
RegisterNotificationDeviceInteractor,
RegisterNotificationDeviceRequest,
)
from template_project.application.notification_device.interactors.send_notification import (
NotificationInteractor,
SendNotificationRequest,
)
from template_project.application.user.notification_device.errors import NotificationDeviceNotFoundError
security = HTTPBearer()
router = APIRouter(route_class=DishkaRoute, tags=["Notifications"], dependencies=[Depends(security)])
@@ -19,6 +23,10 @@ class SendNotificationRequestModel(BaseModel):
body: str
class RegisterNotificationDeviceRequestModel(BaseModel):
device_id: str
@router.post("/notifications/send")
async def send_notification(
request: SendNotificationRequestModel,
@@ -29,3 +37,12 @@ async def send_notification(
await interactor.send_notification(notification_request)
except NotificationDeviceNotFoundError as error:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Notification device not found") from error
@router.post("/notifications/register-device")
async def register_notification_device(
request: RegisterNotificationDeviceRequestModel,
interactor: FromDishka[RegisterNotificationDeviceInteractor],
) -> None:
register_request = RegisterNotificationDeviceRequest(device_id=request.device_id)
await interactor.execute(register_request)