39 lines
1.2 KiB
Python
39 lines
1.2 KiB
Python
from sqlalchemy import text
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
from api.domain.user import User, UserRepository
|
|
from api.infrastructure.persistence.models.user import UserModel
|
|
|
|
|
|
class SqlAlchemyUserRepository(UserRepository):
|
|
def __init__(self, session: AsyncSession) -> None:
|
|
self.session = session
|
|
|
|
async def create_user(self, user: User) -> None:
|
|
# stmt = insert(UserModel).values(
|
|
# id=user.id.value,
|
|
# name=user.name.value,
|
|
# email=user.email.value,
|
|
# hashed_password=user.hashed_password,
|
|
# )
|
|
stmt = text(
|
|
"""INSERT INTO users (id, name, email, hashed_password)
|
|
VALUES(:id, :name, :email, :hashed_password)
|
|
"""
|
|
)
|
|
await self.session.execute(
|
|
stmt,
|
|
{
|
|
"id": str(user.id.value),
|
|
"name": user.name.value,
|
|
"email": user.email.value,
|
|
"hashed_password": user.hashed_password,
|
|
},
|
|
)
|
|
|
|
async def get_user(self, filter: dict) -> User | None:
|
|
pass
|
|
|
|
async def get_users(self) -> list[User]:
|
|
return []
|