user repo/usecases/session/di
This commit is contained in:
3
api/application/abstractions/__init__.py
Normal file
3
api/application/abstractions/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from .uow import UnitOfWork
|
||||
|
||||
__all__ = ("UnitOfWork",)
|
9
api/application/abstractions/uow.py
Normal file
9
api/application/abstractions/uow.py
Normal file
@@ -0,0 +1,9 @@
|
||||
from typing import Protocol
|
||||
|
||||
|
||||
class UnitOfWork(Protocol):
|
||||
async def commit(self) -> None:
|
||||
raise NotImplementedError
|
||||
|
||||
async def rollback(self) -> None:
|
||||
raise NotImplementedError
|
@@ -1,3 +1,4 @@
|
||||
from .user_response import UserResponse
|
||||
from .user_request import UserCreateRequest
|
||||
from .user_response import UserDetaledResponse, UserResponse
|
||||
|
||||
__all__ = ("UserResponse",)
|
||||
__all__ = ("UserResponse", "UserDetaledResponse", "UserCreateRequest")
|
||||
|
8
api/application/contracts/user/user_request.py
Normal file
8
api/application/contracts/user/user_request.py
Normal file
@@ -0,0 +1,8 @@
|
||||
from dataclasses import dataclass
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class UserCreateRequest:
|
||||
name: str
|
||||
email: str
|
||||
password: str
|
@@ -1,7 +1,16 @@
|
||||
from dataclasses import dataclass
|
||||
from uuid import UUID
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class UserResponse:
|
||||
name: str
|
||||
email: str
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class UserDetaledResponse:
|
||||
id: UUID
|
||||
name: str
|
||||
email: str
|
||||
hashed_password: str
|
||||
|
0
api/application/usecase/__init__.py
Normal file
0
api/application/usecase/__init__.py
Normal file
15
api/application/usecase/create_user.py
Normal file
15
api/application/usecase/create_user.py
Normal file
@@ -0,0 +1,15 @@
|
||||
from api.application.abstractions import UnitOfWork
|
||||
from api.application.contracts.user.user_request import UserCreateRequest
|
||||
from api.domain.user.model import User
|
||||
from api.domain.user.repository import UserRepository
|
||||
|
||||
|
||||
class CreateUser:
|
||||
def __init__(self, uow: UnitOfWork, user_repository: UserRepository) -> None:
|
||||
self.uow = uow
|
||||
self.user_repository = user_repository
|
||||
|
||||
async def execute(self, request: UserCreateRequest) -> None:
|
||||
user = User.create(name=request.name, email=request.email, password=request.password)
|
||||
await self.user_repository.create_user(user=user)
|
||||
await self.uow.commit()
|
Reference in New Issue
Block a user