service_man/api/application/usecase/user/create_user.py

27 lines
901 B
Python
Raw Normal View History

2024-03-31 04:18:41 +03:00
from api.application.abstractions import UnitOfWork
from api.application.contracts.user.user_request import UserCreateRequest
from api.application.protocols.password_hasher import PasswordHasher
2024-03-31 04:18:41 +03:00
from api.domain.user.model import User
from api.domain.user.repository import UserRepository
class CreateUser:
def __init__(
self,
uow: UnitOfWork,
user_repository: UserRepository,
password_hasher: PasswordHasher,
) -> None:
2024-03-31 04:18:41 +03:00
self.uow = uow
self.user_repository = user_repository
self.hasher = password_hasher
2024-03-31 04:18:41 +03:00
async def execute(self, request: UserCreateRequest) -> None:
user = User.create(
name=request.name,
email=request.email,
hashed_password=self.hasher.hash_password(request.password),
)
2024-03-31 04:18:41 +03:00
await self.user_repository.create_user(user=user)
await self.uow.commit()