Products Rendering, removal of deprecated files
This commit is contained in:
@@ -3,7 +3,8 @@ from typing import Optional
|
||||
from aiogram.types import InlineKeyboardButton, InlineKeyboardMarkup
|
||||
from aiogram.utils.keyboard import InlineKeyboardBuilder
|
||||
|
||||
from dto.categories import CategoryDTO
|
||||
from db.models import Category
|
||||
from db.models.products import Product
|
||||
|
||||
|
||||
def cart_btn(user_id: int) -> InlineKeyboardButton:
|
||||
@@ -12,13 +13,15 @@ def cart_btn(user_id: int) -> InlineKeyboardButton:
|
||||
) # TODO: Database integration, get cart items count
|
||||
|
||||
|
||||
def get_back_btn(
|
||||
data: str = "menu:main", text: Optional[str] = "⬅️ Назад"
|
||||
) -> InlineKeyboardButton:
|
||||
return InlineKeyboardButton(text=text, callback_data=data)
|
||||
def get_back_to_catalogue(
|
||||
cat_id: int, *, text: Optional[str] = "⬅️ Назад"
|
||||
) -> InlineKeyboardMarkup:
|
||||
return InlineKeyboardBuilder(
|
||||
[[InlineKeyboardButton(text=text, callback_data=f"cat:{cat_id}")]]
|
||||
).as_markup()
|
||||
|
||||
|
||||
async def main_menu_kb(user_id: int) -> InlineKeyboardMarkup:
|
||||
def main_menu_kb(user_id: int) -> InlineKeyboardMarkup:
|
||||
return InlineKeyboardBuilder(
|
||||
[
|
||||
[
|
||||
@@ -30,8 +33,8 @@ async def main_menu_kb(user_id: int) -> InlineKeyboardMarkup:
|
||||
).as_markup()
|
||||
|
||||
|
||||
async def render_category(
|
||||
children: list[CategoryDTO],
|
||||
def render_category(
|
||||
children: list[Category],
|
||||
parent_id: Optional[int] = None,
|
||||
show_menu: bool = False,
|
||||
) -> InlineKeyboardMarkup:
|
||||
@@ -56,3 +59,48 @@ async def render_category(
|
||||
return InlineKeyboardBuilder(
|
||||
[btns[i : i + 2] for i in range(0, len(children), 2)] + [nav],
|
||||
).as_markup()
|
||||
|
||||
|
||||
def render_products(
|
||||
products: list[Product],
|
||||
*,
|
||||
cat_id: int,
|
||||
page: int = 0,
|
||||
show_prev: Optional[bool] = False,
|
||||
show_next: Optional[bool] = False,
|
||||
) -> InlineKeyboardMarkup:
|
||||
btns = [
|
||||
[InlineKeyboardButton(text=product.name, callback_data=f"product:{product.id}")]
|
||||
for product in products
|
||||
]
|
||||
|
||||
nav = []
|
||||
|
||||
if show_prev:
|
||||
nav.append(
|
||||
InlineKeyboardButton(
|
||||
text="⬅️", callback_data=f"products:{cat_id}:{page - 1}"
|
||||
)
|
||||
)
|
||||
|
||||
nav.append(InlineKeyboardButton(text=str(page), callback_data="..."))
|
||||
|
||||
if show_next:
|
||||
nav.append(
|
||||
InlineKeyboardButton(
|
||||
text="➡️", callback_data=f"products:{cat_id}:{page + 1}"
|
||||
)
|
||||
)
|
||||
|
||||
return InlineKeyboardBuilder(
|
||||
[
|
||||
[
|
||||
InlineKeyboardButton(
|
||||
text="⬅️ Назад",
|
||||
callback_data=f"cat:{cat_id}",
|
||||
)
|
||||
]
|
||||
]
|
||||
+ btns
|
||||
+ [nav]
|
||||
).as_markup()
|
||||
|
||||
Reference in New Issue
Block a user