._.
This commit is contained in:
parent
674fe63a1f
commit
14d07f25fd
@ -11,7 +11,9 @@ class TotalOrderEntity(BaseModel):
|
||||
price: float
|
||||
user_id: int
|
||||
status_id: int
|
||||
delivery_orders: Optional[List[int]] = None #
|
||||
user_login: Optional[str] = None
|
||||
status_name: Optional[str] = None
|
||||
delivery_orders: Optional[List[int]] = None
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
@ -12,7 +12,7 @@ class TotalOrdersService:
|
||||
self.repository = TotalOrdersRepository(db)
|
||||
|
||||
def get_all_total_orders(self) -> List[TotalOrderEntity]:
|
||||
total_orders = self.repository.get_all()
|
||||
total_orders = self.repository.get_all_with_users_and_statuses()
|
||||
return [
|
||||
TotalOrderEntity(
|
||||
id=order.id,
|
||||
@ -22,7 +22,9 @@ class TotalOrdersService:
|
||||
price=order.price,
|
||||
user_id=order.user_id,
|
||||
status_id=order.status_id,
|
||||
delivery_orders=[do.id for do in order.delivery_orders] if order.delivery_orders else []
|
||||
delivery_orders=[do.id for do in order.delivery_orders] if order.delivery_orders else [],
|
||||
user_login=order.user.login,
|
||||
status_name=order.status.name,
|
||||
)
|
||||
for order in total_orders
|
||||
]
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
from sqlalchemy.orm import Session
|
||||
from sqlalchemy.orm import Session, joinedload
|
||||
from app.infrastructure.database.models.total_orders import TotalOrder
|
||||
|
||||
|
||||
@ -9,6 +9,12 @@ class TotalOrdersRepository:
|
||||
def get_all(self):
|
||||
return self.db.query(TotalOrder).all()
|
||||
|
||||
def get_all_with_users_and_statuses(self):
|
||||
return self.db.query(TotalOrder) \
|
||||
.options(joinedload(TotalOrder.user)) \
|
||||
.options(joinedload(TotalOrder.status)) \
|
||||
.all()
|
||||
|
||||
def get_by_id(self, total_order_id: int):
|
||||
return self.db.query(TotalOrder).filter(TotalOrder.id == total_order_id).first()
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user