create interface uow update services to uow

This commit is contained in:
IluaAir
2025-07-11 21:48:42 +03:00
parent 61512f70d4
commit b12bb65268
5 changed files with 20 additions and 8 deletions

View File

@@ -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
View 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:
...

View File

@@ -17,4 +17,3 @@ class UserRequest(BaseModel):
username: str username: str
email: EmailStr | None = None email: EmailStr | None = None
password: str password: str

View File

@@ -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