create interface uow update services to uow
This commit is contained in:
@@ -4,7 +4,7 @@ from fastapi import Depends
|
|||||||
from sqlalchemy.ext.asyncio import AsyncSession
|
from sqlalchemy.ext.asyncio import AsyncSession
|
||||||
|
|
||||||
from src.core.database import async_session_maker
|
from src.core.database import async_session_maker
|
||||||
from src.utils.db_manager import DBManager
|
from src.core.db_manager import DBManager
|
||||||
|
|
||||||
|
|
||||||
async def get_db() -> AsyncGenerator[AsyncSession, None]:
|
async def get_db() -> AsyncGenerator[AsyncSession, None]:
|
||||||
@@ -13,5 +13,3 @@ async def get_db() -> AsyncGenerator[AsyncSession, None]:
|
|||||||
|
|
||||||
|
|
||||||
sessionDep = Annotated[AsyncSession, Depends(get_db)]
|
sessionDep = Annotated[AsyncSession, Depends(get_db)]
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
16
src/core/interfaces.py
Normal file
16
src/core/interfaces.py
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
from typing import Protocol
|
||||||
|
|
||||||
|
from src.repository.users import UsersRepo
|
||||||
|
|
||||||
|
|
||||||
|
class IUnitOfWork(Protocol):
|
||||||
|
user: UsersRepo
|
||||||
|
|
||||||
|
async def __aenter__(self) -> "IUnitOfWork":
|
||||||
|
...
|
||||||
|
|
||||||
|
async def __aexit__(self, exc_type, exc_val, exc_tb) -> None:
|
||||||
|
...
|
||||||
|
|
||||||
|
async def commit(self) -> None:
|
||||||
|
...
|
||||||
@@ -17,4 +17,3 @@ class UserRequest(BaseModel):
|
|||||||
username: str
|
username: str
|
||||||
email: EmailStr | None = None
|
email: EmailStr | None = None
|
||||||
password: str
|
password: str
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
from src.utils.db_manager import DBManager
|
from src.core.interfaces import IUnitOfWork
|
||||||
|
|
||||||
|
|
||||||
class BaseService:
|
class BaseService:
|
||||||
session: DBManager | None
|
session: IUnitOfWork | None
|
||||||
|
|
||||||
def __init__(self, session: DBManager):
|
def __init__(self, session: "IUnitOfWork"):
|
||||||
self.session = session
|
self.session = session
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user