enum
parent
76cf6950ae
commit
6387083e63
|
@ -1,15 +0,0 @@
|
||||||
from enum import Enum
|
|
||||||
|
|
||||||
|
|
||||||
class UserRole(Enum):
|
|
||||||
# base roles
|
|
||||||
ADMIN = "Administrator"
|
|
||||||
|
|
||||||
# service provider roles
|
|
||||||
SUPPLIER_EMPLOYER = "Director"
|
|
||||||
SUPPLIER = "Supplie of service"
|
|
||||||
SUPPLIER_EMPLOYEE = "Supplie employee"
|
|
||||||
|
|
||||||
CLIENT = "Client"
|
|
||||||
EMPLOYER = "Client company employer"
|
|
||||||
EMPLOYEE = "Client company employee"
|
|
|
@ -1,5 +1,6 @@
|
||||||
import re
|
import re
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
|
from enum import Enum
|
||||||
from uuid import UUID, uuid4
|
from uuid import UUID, uuid4
|
||||||
|
|
||||||
from api.domain import DomainValidationError
|
from api.domain import DomainValidationError
|
||||||
|
@ -7,6 +8,20 @@ from api.domain.entity import DomainEntity
|
||||||
from api.domain.value_obj import DomainValueObject
|
from api.domain.value_obj import DomainValueObject
|
||||||
|
|
||||||
|
|
||||||
|
class Roles(Enum):
|
||||||
|
# base roles
|
||||||
|
ADMIN = "Administrator"
|
||||||
|
|
||||||
|
# service provider roles
|
||||||
|
SUPPLIER_EMPLOYER = "Director"
|
||||||
|
SUPPLIER = "Supplie of service"
|
||||||
|
SUPPLIER_EMPLOYEE = "Supplie employee"
|
||||||
|
|
||||||
|
CLIENT = "Client"
|
||||||
|
EMPLOYER = "Client company employer"
|
||||||
|
EMPLOYEE = "Client company employee"
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True)
|
@dataclass(frozen=True)
|
||||||
class UserEmail(DomainValueObject):
|
class UserEmail(DomainValueObject):
|
||||||
value: str
|
value: str
|
||||||
|
@ -15,7 +30,9 @@ class UserEmail(DomainValueObject):
|
||||||
pattern = r"^[\w\.-]+@[a-zA-Z\d\.-]+\.[a-zA-Z]{2,}$"
|
pattern = r"^[\w\.-]+@[a-zA-Z\d\.-]+\.[a-zA-Z]{2,}$"
|
||||||
|
|
||||||
if not re.match(pattern, self.value):
|
if not re.match(pattern, self.value):
|
||||||
raise DomainValidationError("Invalid email format. Email must be in the format 'example@example.com'.")
|
raise DomainValidationError(
|
||||||
|
"Invalid email format. Email must be in the format 'example@example.com'."
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True)
|
@dataclass(frozen=True)
|
||||||
|
@ -26,7 +43,9 @@ class UserFirstName(DomainValueObject):
|
||||||
if len(self.value) < 1:
|
if len(self.value) < 1:
|
||||||
raise DomainValidationError("First name must be at least 1 character long.")
|
raise DomainValidationError("First name must be at least 1 character long.")
|
||||||
if len(self.value) > 100:
|
if len(self.value) > 100:
|
||||||
raise DomainValidationError("First name must be at most 100 characters long.")
|
raise DomainValidationError(
|
||||||
|
"First name must be at most 100 characters long."
|
||||||
|
)
|
||||||
if not self.value.isalpha():
|
if not self.value.isalpha():
|
||||||
raise DomainValidationError("First name must only contain letters.")
|
raise DomainValidationError("First name must only contain letters.")
|
||||||
|
|
||||||
|
@ -39,7 +58,9 @@ class UserLastName(DomainValueObject):
|
||||||
if len(self.value) < 1:
|
if len(self.value) < 1:
|
||||||
raise DomainValidationError("Last name must be at least 1 character long.")
|
raise DomainValidationError("Last name must be at least 1 character long.")
|
||||||
if len(self.value) > 100:
|
if len(self.value) > 100:
|
||||||
raise DomainValidationError("Last name must be at most 100 characters long.")
|
raise DomainValidationError(
|
||||||
|
"Last name must be at most 100 characters long."
|
||||||
|
)
|
||||||
if not self.value.isalpha():
|
if not self.value.isalpha():
|
||||||
raise DomainValidationError("Last name must only contain letters.")
|
raise DomainValidationError("Last name must only contain letters.")
|
||||||
|
|
||||||
|
@ -49,6 +70,11 @@ class UserId(DomainValueObject):
|
||||||
value: UUID
|
value: UUID
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True)
|
||||||
|
class UserRole(DomainValueObject):
|
||||||
|
roles: list[Roles]
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class User(DomainEntity[UserId]):
|
class User(DomainEntity[UserId]):
|
||||||
name: UserFirstName
|
name: UserFirstName
|
||||||
|
|
Loading…
Reference in New Issue