feat: products quantity and total price in deal schemas

This commit is contained in:
2025-10-11 16:22:38 +04:00
parent 636821e74a
commit d8eba188c9
3 changed files with 84 additions and 7 deletions

View File

@ -26,7 +26,7 @@ class DealService(
sorting: SortingSchema,
*filters,
) -> GetDealsResponse:
deals, total_items = await self.repository.get_all(
rows, total_items = await self.repository.get_all(
pagination.page,
pagination.items_per_page,
sorting.field,
@ -38,8 +38,17 @@ class DealService(
if pagination.items_per_page:
total_pages = math.ceil(total_items / pagination.items_per_page)
deals = [
DealSchema(
**deal.__dict__,
products_quantity=products_quantity,
total_price=total_price,
)
for deal, total_price, products_quantity in rows
]
return GetDealsResponse(
items=[DealSchema.model_validate(deal) for deal in deals],
items=deals,
pagination_info=PaginationInfoSchema(
total_pages=total_pages, total_items=total_items
),