Files
shveitechbot/handlers/client/menu.py

46 lines
1.2 KiB
Python

from aiogram import Router, F
from aiogram.types import CallbackQuery, Message
from aiogram.filters import Command
from aiogram.fsm.context import FSMContext
from sqlalchemy.ext.asyncio import AsyncSession
from misc.kb import main_menu_kb
from repositories.order_items import OrderItemRepository
from services.orders import OrderService
router = Router()
@router.message(Command("start"))
async def main_menu(
msg: Message,
state: FSMContext,
session: AsyncSession,
order_items_repo: OrderItemRepository,
):
await state.clear()
cart_items = await order_items_repo.get_items_count_by_customer(
session, msg.from_user.id
)
await msg.answer(
"hii!", reply_markup=main_menu_kb(cart_items)
) # TODO: Write a welcome message
@router.callback_query(F.data.startswith("menu:"))
async def main_menu_cb(
cb: CallbackQuery,
state: FSMContext,
session: AsyncSession,
order_items_repo: OrderService,
):
await state.clear()
cart_items = await order_items_repo.get_items_count_by_customer(
session, cb.from_user.id
)
await cb.message.edit_text(
"hii!", reply_markup=main_menu_kb(cart_items)
) # TODO: Write a welcome message