Companies
This commit is contained in:
49
app/domain/company.py
Normal file
49
app/domain/company.py
Normal file
@ -0,0 +1,49 @@
|
||||
from __future__ import annotations
|
||||
|
||||
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"
|
||||
|
||||
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]
|
||||
Reference in New Issue
Block a user