add getting company
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
from .base import Base
|
||||
from .company import CompanyModel
|
||||
from .user import UserModel
|
||||
|
||||
__all__ = (
|
||||
"Base",
|
||||
"UserModel",
|
||||
"CompanyModel",
|
||||
)
|
||||
|
17
api/infrastructure/persistence/models/company.py
Normal file
17
api/infrastructure/persistence/models/company.py
Normal file
@@ -0,0 +1,17 @@
|
||||
import uuid
|
||||
|
||||
from sqlalchemy import UUID
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
from api.infrastructure.persistence.models.base import Base
|
||||
|
||||
|
||||
class CompanyModel(Base):
|
||||
__tablename__ = "companies"
|
||||
|
||||
id: Mapped[uuid.UUID] = mapped_column(
|
||||
UUID(as_uuid=True),
|
||||
primary_key=True,
|
||||
)
|
||||
name: Mapped[str]
|
||||
email: Mapped[str] = mapped_column(unique=True)
|
@@ -1,45 +1,45 @@
|
||||
# from sqlalchemy import text
|
||||
# from sqlalchemy.ext.asyncio import AsyncSession
|
||||
#
|
||||
# from api.domain.company import CompanyRepository, company
|
||||
# from api.domain.user.model import UserEmail, UserFirstName, UserId
|
||||
#
|
||||
#
|
||||
# class SqlAlchemyUserRepository(UserRepository):
|
||||
# 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 get_user(self, filter: dict) -> User | None:
|
||||
# stmt = text("""SELECT * FROM users WHERE email = :val""")
|
||||
# result = await self.session.execute(stmt, {"val": filter["email"]})
|
||||
#
|
||||
# result = result.mappings().one_or_none()
|
||||
#
|
||||
# if result is None:
|
||||
# return None
|
||||
#
|
||||
# return User(
|
||||
# id=UserId(result.id),
|
||||
# name=UserFirstName(result.name),
|
||||
# email=UserEmail(result.email),
|
||||
# hashed_password=result.hashed_password,
|
||||
# )
|
||||
#
|
||||
from sqlalchemy import text
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from api.domain.company.model import Company, CompanyEmail, CompanyId, CompanyName
|
||||
from api.domain.company.repository import CompanyRepository
|
||||
|
||||
|
||||
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 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"]})
|
||||
|
||||
result = result.mappings().all()
|
||||
|
||||
return [
|
||||
Company(
|
||||
id=CompanyId(c.id),
|
||||
name=CompanyName(c.name),
|
||||
email=CompanyEmail(c.email),
|
||||
)
|
||||
for c in result
|
||||
]
|
||||
|
||||
|
||||
# async def get_users(self) -> list[User]:
|
||||
# return []
|
||||
|
Reference in New Issue
Block a user