Files
eryao/backend/src/v1/auth/service.py
T

51 lines
1.4 KiB
Python
Raw Normal View History

from __future__ import annotations
from typing import Protocol
from v1.auth.schemas import (
EmailSessionCreateRequest,
OtpSendRequest,
SessionRefreshRequest,
SessionResponse,
)
class AuthServiceGateway(Protocol):
async def send_otp(self, request: OtpSendRequest) -> None:
raise NotImplementedError
async def create_email_session(
self, request: EmailSessionCreateRequest
) -> SessionResponse:
raise NotImplementedError
async def refresh_session(self, request: SessionRefreshRequest) -> SessionResponse:
raise NotImplementedError
async def delete_session(self, refresh_token: str | None) -> None:
raise NotImplementedError
class AuthService:
_gateway: AuthServiceGateway
def __init__(
self,
gateway: AuthServiceGateway,
) -> None:
self._gateway = gateway
async def send_otp(self, request: OtpSendRequest) -> None:
await self._gateway.send_otp(request)
async def create_email_session(
self, request: EmailSessionCreateRequest
) -> SessionResponse:
return await self._gateway.create_email_session(request)
async def refresh_session(self, request: SessionRefreshRequest) -> SessionResponse:
return await self._gateway.refresh_session(request)
async def delete_session(self, refresh_token: str | None) -> None:
await self._gateway.delete_session(refresh_token)