2023-04-01 16:19:12 +02:00
|
|
|
from typing import Annotated, Any
|
|
|
|
from fastapi import Depends
|
|
|
|
from sqlalchemy.ext.asyncio import async_sessionmaker
|
|
|
|
from ..db import get_session
|
2024-05-21 11:11:47 +02:00
|
|
|
from ..auth import get_current_user, authorize_api_key
|
2023-04-01 16:19:12 +02:00
|
|
|
from ..domain.user import User
|
|
|
|
|
|
|
|
|
|
|
|
AsyncSession = Annotated[async_sessionmaker, Depends(get_session)]
|
|
|
|
UserDependency = Annotated[User, Depends(get_current_user)]
|
2024-05-21 15:18:03 +02:00
|
|
|
ApiKeyDependency = Annotated[None, Depends(authorize_api_key)]
|
2023-04-01 16:19:12 +02:00
|
|
|
|
|
|
|
|
|
|
|
class BaseController:
|
|
|
|
def __init__(self, session: AsyncSession) -> None:
|
|
|
|
self.async_session = session
|
|
|
|
|
|
|
|
async def call(self, *args, **kwargs) -> Any:
|
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
async def __call__(self, *args, **kwargs) -> Any:
|
|
|
|
return await self.call(*args, **kwargs)
|
|
|
|
|
|
|
|
|
|
|
|
class AuthorizedController(BaseController):
|
|
|
|
def __init__(self, session: AsyncSession, user: UserDependency) -> None:
|
|
|
|
super().__init__(session)
|
|
|
|
self.user = user
|
2024-05-21 11:11:47 +02:00
|
|
|
|
|
|
|
|
|
|
|
class TasksSessionController(BaseController):
|
|
|
|
def __init__(self, session: AsyncSession, api_key: ApiKeyDependency) -> None:
|
|
|
|
super().__init__(session)
|