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.model import User from api.domain.user.repository import UserRepository class CreateUser: def __init__( self, transaction: TransactionContextManager, user_repository: UserRepository, password_hasher: PasswordHasher, ) -> None: self.transaction = transaction self.user_repository = user_repository self.hasher = password_hasher async def execute(self, request: UserCreateRequest) -> None: user = User.create( name=request.name, last_name=request.last_name, email=request.email, hashed_password=self.hasher.hash_password(request.password), ) async with self.transaction as tr: await self.user_repository.create_user(user=user) await tr.commit()