This commit is contained in:
Андрей Дувакин 2024-10-05 13:57:01 +05:00
parent 215eddda32
commit d573369114
3 changed files with 9 additions and 9 deletions

View File

@ -6,7 +6,6 @@ class StatusEntity(BaseModel):
id: Optional[int] = None
name: str
orders: Optional[List[int]] = None
steps: Optional[List[int]] = None
class Config:
from_attributes = True

View File

@ -17,8 +17,7 @@ class StatusesService:
StatusEntity(
id=status.id,
name=status.name,
orders=[order.id for order in status.orders] if status.orders else [],
steps=[step.id for step in status.steps] if status.steps else []
orders=[order.id for order in status.total_orders] if status.total_orders else [],
)
for status in statuses
]
@ -29,8 +28,7 @@ class StatusesService:
return StatusEntity(
id=status.id,
name=status.name,
orders=[order.id for order in status.orders] if status.orders else [],
steps=[step.id for step in status.steps] if status.steps else []
orders=[order.id for order in status.total_orders] if status.total_orders else [],
)
return None
@ -43,7 +41,6 @@ class StatusesService:
id=created_status.id,
name=created_status.name,
orders=[],
steps=[]
)
def update_status(self, status_id: int, entity: StatusEntity) -> Optional[StatusEntity]:
@ -54,8 +51,7 @@ class StatusesService:
return StatusEntity(
id=status_model.id,
name=status_model.name,
orders=[order.id for order in status_model.orders] if status_model.orders else [],
steps=[step.id for step in status_model.steps] if status_model.steps else []
orders=[order.id for order in status_model.total_orders] if status_model.total_orders else [],
)
return None

View File

@ -1,4 +1,4 @@
from sqlalchemy.orm import Session
from sqlalchemy.orm import Session, joinedload
from app.infrastructure.database.models.statuses import Status
@ -9,6 +9,11 @@ class StatusesRepository:
def get_all(self):
return self.db.query(Status).all()
def get_all_with_orders(self):
return self.db.query(Status) \
.options(joinedload(Status.total_orders)) \
.all()
def get_by_id(self, status_id: int):
return self.db.query(Status).filter(Status.id == status_id).first()