48 lines
1.4 KiB
Python
48 lines
1.4 KiB
Python
from typing import Annotated
|
|
|
|
from litestar.contrib.repository import FilterTypes
|
|
from litestar.contrib.sqlalchemy.base import BigIntBase
|
|
from litestar.contrib.sqlalchemy.dto import SQLAlchemyDTO
|
|
from litestar.contrib.sqlalchemy.repository import SQLAlchemyAsyncRepository
|
|
from litestar.contrib.sqlalchemy.repository.types import SelectT
|
|
from litestar.dto import DTOConfig
|
|
from sqlalchemy import true
|
|
from sqlalchemy.orm import Mapped
|
|
|
|
from app.lib import service
|
|
|
|
|
|
class Company(BigIntBase):
|
|
__tablename__ = "vending_companies" # type: ignore[assignment]
|
|
|
|
caption: Mapped[str]
|
|
address: Mapped[str]
|
|
city: Mapped[str]
|
|
phone: Mapped[str]
|
|
enabled: Mapped[str]
|
|
country_code: Mapped[str]
|
|
external_id: Mapped[str]
|
|
alive: Mapped[bool]
|
|
|
|
|
|
class Repository(SQLAlchemyAsyncRepository[Company]):
|
|
model_type = Company
|
|
|
|
def _apply_filters(
|
|
self, *filters: FilterTypes, apply_pagination: bool = True, statement: SelectT
|
|
) -> SelectT:
|
|
statement = super()._apply_filters(
|
|
*filters, apply_pagination=apply_pagination, statement=statement
|
|
)
|
|
statement = statement.where(self.model_type.alive == true())
|
|
return statement
|
|
|
|
|
|
class Service(service.Service[Company]):
|
|
repository_type = Repository
|
|
|
|
|
|
write_config = DTOConfig()
|
|
CompanyWriteDTO = SQLAlchemyDTO[Annotated[Company, write_config]]
|
|
CompanyReadDTO = SQLAlchemyDTO[Company]
|