init
This commit is contained in:
21
app/domain/users/value_objects.py
Normal file
21
app/domain/users/value_objects.py
Normal file
@@ -0,0 +1,21 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import re
|
||||
from dataclasses import dataclass
|
||||
|
||||
from app.domain.shared.base_value_object import ValueObject
|
||||
from app.domain.users.exceptions import InvalidEmail
|
||||
|
||||
_EMAIL_RE = re.compile(r"^[^@\s]+@[^@\s]+\.[^@\s]+$")
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class Email(ValueObject):
|
||||
value: str
|
||||
|
||||
def __post_init__(self) -> None:
|
||||
if not _EMAIL_RE.match(self.value):
|
||||
raise InvalidEmail(f"Invalid email: {self.value}")
|
||||
|
||||
def __str__(self) -> str:
|
||||
return self.value
|
||||
Reference in New Issue
Block a user