From 472fcf4f9d17b7a15f67f703eb423926258c98ad Mon Sep 17 00:00:00 2001 From: KKlochko Date: Thu, 22 Jun 2023 11:22:58 +0300 Subject: [PATCH] Add the order handler. --- src/handlers/__init__.py | 4 ++++ src/handlers/cart.py | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/handlers/__init__.py b/src/handlers/__init__.py index 3672251..948b8b0 100644 --- a/src/handlers/__init__.py +++ b/src/handlers/__init__.py @@ -6,6 +6,7 @@ from src.handlers.city import city_list_handler, select_city_handler from src.handlers.company import company_list_handler, select_company_handler from src.handlers.category import category_list_handler from src.handlers.cart import cart_list_handler, add_item_handler +from src.handlers.cart import order_handler from src.handlers.user import register_handler from src.fmt.city_formatter import CityFormatter @@ -62,3 +63,6 @@ def setup(bot: botlib.Bot, prefix: str): count = int(count) await add_item_handler(bot=bot, room_id=room.room_id, sender=message.sender, admin_id=bot.config.admin_id, item_name=name, count=count) + if match.command('order'): + await order_handler(bot=bot, room_id=room.room_id, sender=message.sender, admin_id=bot.config.admin_id) + diff --git a/src/handlers/cart.py b/src/handlers/cart.py index 8a59bda..1a28a90 100644 --- a/src/handlers/cart.py +++ b/src/handlers/cart.py @@ -8,6 +8,7 @@ from src.api.v2.cart_api import CartAPI from src.fetcher.v2.api_fetcher import ApiFetcher from src.fmt.item_formatter import ItemFormatter from src.fmt.cart_item_formatter import CartItemFormatter +from src.fmt.order_formatter import OrderFormatter dots_bot_api_config = DotsBotApiConfig() @@ -22,6 +23,17 @@ async def cart_list_handler(room_id: str, bot: botlib.Bot, sender: str, admin_id await bot.api.send_markdown_message(room_id=room_id, message=msg) +async def order_handler(room_id: str, bot: botlib.Bot, sender: str, admin_id: str): + + session = aiohttp.ClientSession(json_serialize=ujson.dumps) + apiFetcher = ApiFetcher(dots_bot_api_config.get_base_url(), session) + formatter = OrderFormatter() + cartAPI = CartAPI(apiFetcher, formatter) + + msg: str = await cartAPI.get_order_message(sender) + + await bot.api.send_markdown_message(room_id=room_id, message=msg) + async def add_item_handler(room_id: str, bot: botlib.Bot, sender: str, admin_id: str, item_name: str, count: int): session = aiohttp.ClientSession(json_serialize=ujson.dumps)