sync
This commit is contained in:
@@ -1,30 +1,33 @@
|
||||
from sqlalchemy import text
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from api.domain.company.model import Company, CompanyEmail, CompanyId, CompanyName
|
||||
from api.domain.company.model import (Company, CompanyAddress, CompanyEmail,
|
||||
CompanyId, CompanyName)
|
||||
from api.domain.company.repository import CompanyRepository
|
||||
from api.domain.user.model import UserId
|
||||
|
||||
|
||||
class SqlAlchemyCompanyRepository(CompanyRepository):
|
||||
def __init__(self, session: AsyncSession) -> None:
|
||||
self.session = session
|
||||
|
||||
# async def create_user(self, user: User) -> None:
|
||||
# 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 create_company(self, company: Company) -> None:
|
||||
stmt = text(
|
||||
"""INSERT INTO company (id, name, email, address, owner_id)
|
||||
VALUES(:id, :name, :email, :address, :owner_id)
|
||||
"""
|
||||
)
|
||||
await self.session.execute(
|
||||
stmt,
|
||||
{
|
||||
"id": str(company.id.value),
|
||||
"name": company.name.value,
|
||||
"email": company.email.value,
|
||||
"address": company.address.value,
|
||||
"owner_id": str(company.owner_id.value),
|
||||
},
|
||||
)
|
||||
|
||||
async def get_companies_by_owner_email(self, filter: dict) -> list[Company]:
|
||||
stmt = text("""SELECT * FROM companies WHERE email = :val""")
|
||||
result = await self.session.execute(stmt, {"val": filter["email"]})
|
||||
@@ -36,6 +39,8 @@ class SqlAlchemyCompanyRepository(CompanyRepository):
|
||||
id=CompanyId(c.id),
|
||||
name=CompanyName(c.name),
|
||||
email=CompanyEmail(c.email),
|
||||
address=CompanyAddress(c.address),
|
||||
owner_id=UserId(c.owner_id),
|
||||
)
|
||||
for c in result
|
||||
]
|
||||
|
@@ -2,7 +2,8 @@ from sqlalchemy import text
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from api.domain.user import User, UserRepository
|
||||
from api.domain.user.model import UserEmail, UserFirstName, UserId
|
||||
from api.domain.user.model import (UserEmail, UserFirstName, UserId,
|
||||
UserLastName)
|
||||
|
||||
|
||||
class SqlAlchemyUserRepository(UserRepository):
|
||||
@@ -11,8 +12,8 @@ class SqlAlchemyUserRepository(UserRepository):
|
||||
|
||||
async def create_user(self, user: User) -> None:
|
||||
stmt = text(
|
||||
"""INSERT INTO users (id, name, email, hashed_password)
|
||||
VALUES(:id, :name, :email, :hashed_password)
|
||||
"""INSERT INTO users (id, name, last_name, email, hashed_password)
|
||||
VALUES(:id, :name, :last_name, :email, :hashed_password)
|
||||
"""
|
||||
)
|
||||
await self.session.execute(
|
||||
@@ -20,6 +21,7 @@ class SqlAlchemyUserRepository(UserRepository):
|
||||
{
|
||||
"id": str(user.id.value),
|
||||
"name": user.name.value,
|
||||
"last_name": user.last_name.value,
|
||||
"email": user.email.value,
|
||||
"hashed_password": user.hashed_password,
|
||||
},
|
||||
@@ -37,6 +39,7 @@ class SqlAlchemyUserRepository(UserRepository):
|
||||
return User(
|
||||
id=UserId(result.id),
|
||||
name=UserFirstName(result.name),
|
||||
last_name=UserLastName(result.last_name),
|
||||
email=UserEmail(result.email),
|
||||
hashed_password=result.hashed_password,
|
||||
)
|
||||
|
Reference in New Issue
Block a user