._.
This commit is contained in:
parent
215eddda32
commit
d573369114
@ -6,7 +6,6 @@ class StatusEntity(BaseModel):
|
|||||||
id: Optional[int] = None
|
id: Optional[int] = None
|
||||||
name: str
|
name: str
|
||||||
orders: Optional[List[int]] = None
|
orders: Optional[List[int]] = None
|
||||||
steps: Optional[List[int]] = None
|
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
from_attributes = True
|
from_attributes = True
|
||||||
|
|||||||
@ -17,8 +17,7 @@ class StatusesService:
|
|||||||
StatusEntity(
|
StatusEntity(
|
||||||
id=status.id,
|
id=status.id,
|
||||||
name=status.name,
|
name=status.name,
|
||||||
orders=[order.id for order in status.orders] if status.orders else [],
|
orders=[order.id for order in status.total_orders] if status.total_orders else [],
|
||||||
steps=[step.id for step in status.steps] if status.steps else []
|
|
||||||
)
|
)
|
||||||
for status in statuses
|
for status in statuses
|
||||||
]
|
]
|
||||||
@ -29,8 +28,7 @@ class StatusesService:
|
|||||||
return StatusEntity(
|
return StatusEntity(
|
||||||
id=status.id,
|
id=status.id,
|
||||||
name=status.name,
|
name=status.name,
|
||||||
orders=[order.id for order in status.orders] if status.orders else [],
|
orders=[order.id for order in status.total_orders] if status.total_orders else [],
|
||||||
steps=[step.id for step in status.steps] if status.steps else []
|
|
||||||
)
|
)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@ -43,7 +41,6 @@ class StatusesService:
|
|||||||
id=created_status.id,
|
id=created_status.id,
|
||||||
name=created_status.name,
|
name=created_status.name,
|
||||||
orders=[],
|
orders=[],
|
||||||
steps=[]
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def update_status(self, status_id: int, entity: StatusEntity) -> Optional[StatusEntity]:
|
def update_status(self, status_id: int, entity: StatusEntity) -> Optional[StatusEntity]:
|
||||||
@ -54,8 +51,7 @@ class StatusesService:
|
|||||||
return StatusEntity(
|
return StatusEntity(
|
||||||
id=status_model.id,
|
id=status_model.id,
|
||||||
name=status_model.name,
|
name=status_model.name,
|
||||||
orders=[order.id for order in status_model.orders] if status_model.orders else [],
|
orders=[order.id for order in status_model.total_orders] if status_model.total_orders else [],
|
||||||
steps=[step.id for step in status_model.steps] if status_model.steps else []
|
|
||||||
)
|
)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session, joinedload
|
||||||
from app.infrastructure.database.models.statuses import Status
|
from app.infrastructure.database.models.statuses import Status
|
||||||
|
|
||||||
|
|
||||||
@ -9,6 +9,11 @@ class StatusesRepository:
|
|||||||
def get_all(self):
|
def get_all(self):
|
||||||
return self.db.query(Status).all()
|
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):
|
def get_by_id(self, status_id: int):
|
||||||
return self.db.query(Status).filter(Status.id == status_id).first()
|
return self.db.query(Status).filter(Status.id == status_id).first()
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user