Done
This commit is contained in:
@ -1,15 +1,12 @@
|
||||
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
|
||||
from app.lib.company_owned_repository import CompanyOwnedRepository
|
||||
|
||||
|
||||
class Machine(BigIntBase):
|
||||
@ -20,26 +17,19 @@ class Machine(BigIntBase):
|
||||
alive: Mapped[bool]
|
||||
deleted: Mapped[bool]
|
||||
external_id: Mapped[str]
|
||||
owner_id: Mapped[int]
|
||||
|
||||
|
||||
class Repository(SQLAlchemyAsyncRepository[Machine]):
|
||||
class Repository(CompanyOwnedRepository[Machine]):
|
||||
model_type = Machine
|
||||
|
||||
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
|
||||
alive_flag = "alive"
|
||||
company_id_field = "owner_id"
|
||||
|
||||
|
||||
class Service(service.Service[Machine]):
|
||||
repository_type = Repository
|
||||
|
||||
|
||||
# write_config = DTOConfig(exclude={"created_at", "updated_at", "nationality"})
|
||||
write_config = DTOConfig()
|
||||
write_config = DTOConfig(exclude={"id"})
|
||||
MachineWriteDTO = SQLAlchemyDTO[Annotated[Machine, write_config]]
|
||||
MachineReadDTO = SQLAlchemyDTO[Machine]
|
||||
|
||||
Reference in New Issue
Block a user