diff --git a/app/core/entities/status.py b/app/core/entities/status.py index 98d29fc..fd828bc 100644 --- a/app/core/entities/status.py +++ b/app/core/entities/status.py @@ -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 diff --git a/app/core/usecases/status_service.py b/app/core/usecases/status_service.py index 5507f56..c7948a2 100644 --- a/app/core/usecases/status_service.py +++ b/app/core/usecases/status_service.py @@ -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 diff --git a/app/infrastructure/database/repository/status_repository.py b/app/infrastructure/database/repository/status_repository.py index fa9a753..58d759d 100644 --- a/app/infrastructure/database/repository/status_repository.py +++ b/app/infrastructure/database/repository/status_repository.py @@ -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()