Files
RekomenciBackend/src/template_project/application/auth_identity/entity.py
T
2025-11-18 00:25:24 +03:00

41 lines
953 B
Python

from datetime import UTC, datetime
from enum import StrEnum
from typing import NewType, Self
from uuid import UUID
from uuid_utils.compat import uuid7
from template_project.application.common.entity import Entity, to_entity
from template_project.application.user.entity import UserId
AuthIdentityId = NewType("AuthIdentityId", UUID)
class AuthMethod(StrEnum):
EMAIL = "email"
@to_entity
class AuthIdentity(Entity[AuthIdentityId]):
user_id: UserId
method: AuthMethod
identifier: str
secret_key: str | None
@classmethod
def factory(
cls,
user_id: UserId,
method: AuthMethod,
identifier: str,
secret_key: str | None = None,
) -> Self:
return cls(
id=AuthIdentityId(uuid7()),
user_id=user_id,
method=method,
identifier=identifier,
secret_key=secret_key,
created_at=datetime.now(tz=UTC),
)