You've already forked RekomenciBackend
feat(): profiles
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
from typing import override
|
||||
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from template_project.adapters.data_gateways.tables import profile_table
|
||||
from template_project.application.user.entity import UserId
|
||||
from template_project.application.user.profile.data_gateway import ProfileDataGateway
|
||||
from template_project.application.user.profile.entity import Profile
|
||||
|
||||
|
||||
class DefaultProfileDataGateway(ProfileDataGateway):
|
||||
def __init__(self, session: AsyncSession) -> None:
|
||||
self._session = session
|
||||
|
||||
@override
|
||||
async def load_by_user_id(self, user_id: UserId) -> Profile | None:
|
||||
statement = select(Profile).where(profile_table.c.user_id == user_id)
|
||||
result = await self._session.execute(statement)
|
||||
return result.scalar_one_or_none()
|
||||
@@ -15,6 +15,7 @@ from sqlalchemy.orm import registry
|
||||
from template_project.application.access_token.entity import AccessToken
|
||||
from template_project.application.auth_identity.entity import AuthIdentity, AuthMethod
|
||||
from template_project.application.user.entity import User
|
||||
from template_project.application.user.profile.entity import Profile
|
||||
|
||||
meta_data = MetaData()
|
||||
mapper_registry = registry()
|
||||
@@ -23,8 +24,6 @@ user_table = Table(
|
||||
"users",
|
||||
meta_data,
|
||||
Column("id", UUID, primary_key=True),
|
||||
Column("email", String, unique=True, nullable=True),
|
||||
Column("hashed_password", String, nullable=True),
|
||||
Column("deleted_at", DateTime(timezone=True)),
|
||||
Column("created_at", DateTime(timezone=True), nullable=False),
|
||||
)
|
||||
@@ -52,6 +51,22 @@ auth_identity_table = Table(
|
||||
UniqueConstraint("method", "identifier", name="uq_auth_method_identifier"),
|
||||
)
|
||||
|
||||
profile_table = Table(
|
||||
"profiles",
|
||||
meta_data,
|
||||
Column("id", UUID, primary_key=True),
|
||||
Column("user_id", UUID, ForeignKey("users.id", ondelete="CASCADE"), nullable=False, unique=True),
|
||||
Column("email", String, nullable=True),
|
||||
Column("display_name", String, nullable=True),
|
||||
Column("first_name", String, nullable=True),
|
||||
Column("last_name", String, nullable=True),
|
||||
Column("avatar_url", String, nullable=True),
|
||||
Column("phone", String, nullable=True),
|
||||
Column("deleted_at", DateTime(timezone=True)),
|
||||
Column("created_at", DateTime(timezone=True), nullable=False),
|
||||
)
|
||||
|
||||
mapper_registry.map_imperatively(User, user_table)
|
||||
mapper_registry.map_imperatively(AccessToken, access_token_table)
|
||||
mapper_registry.map_imperatively(AuthIdentity, auth_identity_table)
|
||||
mapper_registry.map_imperatively(Profile, profile_table)
|
||||
|
||||
Reference in New Issue
Block a user