user repo/usecases/session/di
This commit is contained in:
3
api/domain/__init__.py
Normal file
3
api/domain/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from .error import DomainError
|
||||
|
||||
__all__ = ("DomainError",)
|
4
api/domain/error.py
Normal file
4
api/domain/error.py
Normal file
@@ -0,0 +1,4 @@
|
||||
class DomainError(Exception):
|
||||
def __init__(self, message: str, *args: object) -> None:
|
||||
super().__init__(*args)
|
||||
self.message = message
|
5
api/domain/user/__init__.py
Normal file
5
api/domain/user/__init__.py
Normal file
@@ -0,0 +1,5 @@
|
||||
from .error import UserNotFoundError, UserValidationError
|
||||
from .model import User
|
||||
from .repository import UserRepository
|
||||
|
||||
__all__ = ("UserValidationError", "UserNotFoundError", "User", "UserRepository")
|
9
api/domain/user/error.py
Normal file
9
api/domain/user/error.py
Normal file
@@ -0,0 +1,9 @@
|
||||
from api.domain import DomainError
|
||||
|
||||
|
||||
class UserNotFoundError(DomainError):
|
||||
...
|
||||
|
||||
|
||||
class UserValidationError(DomainError):
|
||||
...
|
33
api/domain/user/model.py
Normal file
33
api/domain/user/model.py
Normal file
@@ -0,0 +1,33 @@
|
||||
from dataclasses import dataclass
|
||||
from uuid import UUID, uuid4
|
||||
|
||||
from api.domain.user import UserValidationError
|
||||
|
||||
|
||||
@dataclass
|
||||
class User:
|
||||
id: UUID
|
||||
name: str
|
||||
email: str
|
||||
password: str
|
||||
|
||||
@staticmethod
|
||||
def create(name: str, email: str, password: str) -> "User":
|
||||
if not name:
|
||||
raise UserValidationError("User name cannot be empty")
|
||||
|
||||
if not email:
|
||||
raise UserValidationError("User email cannot be empty")
|
||||
|
||||
if len(name) > 50:
|
||||
raise UserValidationError("User name cannot be longer than 50 characters")
|
||||
|
||||
if len(email) > 30:
|
||||
raise UserValidationError("User email cannot be longer than 30 characters")
|
||||
|
||||
return User(
|
||||
id=uuid4(),
|
||||
name=name,
|
||||
email=email,
|
||||
password=password,
|
||||
)
|
14
api/domain/user/repository.py
Normal file
14
api/domain/user/repository.py
Normal file
@@ -0,0 +1,14 @@
|
||||
from typing import Protocol
|
||||
|
||||
from api.domain.user.model import User
|
||||
|
||||
|
||||
class UserRepository(Protocol):
|
||||
async def get_user(self, filter: dict) -> User | None:
|
||||
raise NotImplementedError
|
||||
|
||||
async def create_user(self, user: User) -> None:
|
||||
raise NotImplementedError
|
||||
|
||||
async def get_users(self) -> list[User] | None:
|
||||
raise NotImplementedError
|
Reference in New Issue
Block a user