remove fucking uow and replace it by TransactionContextManager
This commit is contained in:
@@ -1,9 +1,6 @@
|
||||
from sqlalchemy.exc import IntegrityError
|
||||
|
||||
from api.application.abstractions import UnitOfWork
|
||||
from api.application.abstractions.transaction import TransactionContextManager
|
||||
from api.application.contracts.auth.auth_request import UserCreateRequest
|
||||
from api.application.protocols.password_hasher import PasswordHasher
|
||||
from api.domain.user.error import UserAlreadyExistsError
|
||||
from api.domain.user.model import User
|
||||
from api.domain.user.repository import UserRepository
|
||||
|
||||
@@ -11,11 +8,11 @@ from api.domain.user.repository import UserRepository
|
||||
class CreateUser:
|
||||
def __init__(
|
||||
self,
|
||||
uow: UnitOfWork,
|
||||
transaction: TransactionContextManager,
|
||||
user_repository: UserRepository,
|
||||
password_hasher: PasswordHasher,
|
||||
) -> None:
|
||||
self.uow = uow
|
||||
self.transaction = transaction
|
||||
self.user_repository = user_repository
|
||||
self.hasher = password_hasher
|
||||
|
||||
@@ -27,13 +24,6 @@ class CreateUser:
|
||||
hashed_password=self.hasher.hash_password(request.password),
|
||||
)
|
||||
|
||||
try:
|
||||
async with self.transaction as tr:
|
||||
await self.user_repository.create_user(user=user)
|
||||
await self.uow.commit()
|
||||
|
||||
except IntegrityError as e:
|
||||
msg = e.args[0].split("\n")[-1]
|
||||
msg = msg.split(":")[1].strip()
|
||||
|
||||
if "email" in msg:
|
||||
raise UserAlreadyExistsError(message=msg)
|
||||
await tr.commit()
|
||||
|
Reference in New Issue
Block a user