Compare commits
3
Commits
5363ca9116
...
472fcf4f9d
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
472fcf4f9d | ||
|
|
b5c58984c5 | ||
|
|
99bf9f07fa |
@@ -56,3 +56,23 @@ class CartAPI:
|
||||
case {"error": error_message}:
|
||||
return error_message
|
||||
|
||||
async def get_order(self, username: str):
|
||||
endpoint = f"/api/v2/order?matrixUsername={username}"
|
||||
|
||||
status, json_data = await self.__fetcher.fetch_json(endpoint)
|
||||
|
||||
if status == 200:
|
||||
return {"ok": json_data}
|
||||
|
||||
return {"error": "Сталася помилка, спробуйте пізніше."}
|
||||
|
||||
async def get_order_message(self, username: str) -> str:
|
||||
response = await self.get_order(username)
|
||||
|
||||
match response:
|
||||
case {"ok": json_data}:
|
||||
return self.__formatter.format(json_data)
|
||||
|
||||
case {"error": error_message}:
|
||||
return error_message
|
||||
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
|
||||
class OrderFormatter():
|
||||
def format(self, order) -> str:
|
||||
id = order['id']
|
||||
order_type = order['delivery']['deliveryTypeText']
|
||||
order_address = order['delivery']['deliveryAddress']
|
||||
item_price = order['prices']['itemsPrice']
|
||||
package_price = order['prices']['packagePrice']
|
||||
delivery_price = order['prices']['deliveryPrice']
|
||||
full_price = order['prices']['fullPrice']
|
||||
return f"Ваше замовлення має id: {id}.\n" \
|
||||
f"Вид доставки: {order_type}.\n" \
|
||||
f"Доставка до: {order_address}.\n" \
|
||||
f"Ціна товарів: {item_price}.\n" \
|
||||
f"Ціна пакування: {package_price}.\n" \
|
||||
f"Ціна доставки: {delivery_price}.\n\n" \
|
||||
f"Остаточна ціна: {full_price}."
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user