catalogue operations, db migr and so on.

pre release version.
This commit is contained in:
2026-03-11 20:26:38 +07:00
parent 1af0cf1826
commit 7f4f8a883d
17 changed files with 284 additions and 63 deletions

View File

@@ -1,5 +1,6 @@
from .inline_mode import router as inline_router
from .menu import router as menu_router
from .product_mgmt import router as product_router
from .creation import router as creation_router
routers = [inline_router, menu_router, product_router]
routers = [inline_router, menu_router, product_router, creation_router]

View File

@@ -0,0 +1,70 @@
from aiogram import F, Router
from aiogram.types import CallbackQuery, Message
from aiogram.fsm.context import FSMContext
from sqlalchemy.ext.asyncio import AsyncSession
from dto.catalogue import NewCategoryContext
from misc.filters import IsVerified
from misc.kb.client import get_back_to_catalogue
from misc.mapper import parse_cat_id
from misc.states import AdminControlStorage
from misc.kb.common import return_menu
from repositories.categories import CategoriesRepository
from services.catalogue import CatalogueService
router = Router()
@router.callback_query(IsVerified(), F.data.startswith("new:"))
async def creation_init(
cb: CallbackQuery,
state: FSMContext,
session: AsyncSession,
catalogue_service: CatalogueService,
):
await state.clear()
data = cb.data.split(":")
mode = data[1]
cat_id = data[2]
path = await catalogue_service.get_path(session, cat_id)
if mode == "category":
await cb.message.edit_text(
f"{path} <i>-> ...</i>\n\n<b>🏷️ Введите название новой категории.</b>",
reply_markup=get_back_to_catalogue(cat_id),
)
ctx = NewCategoryContext(cb.message, cat_id)
await state.set_state(AdminControlStorage.new_category)
await state.set_data({"ctx": ctx})
if mode == "product":
...
@router.message(AdminControlStorage.new_category)
async def create_new_category(
msg: Message,
state: FSMContext,
session: AsyncSession,
categories_repo: CategoriesRepository,
):
await msg.delete()
data = await state.get_data()
ctx: NewCategoryContext | None = data.get("ctx")
if not ctx:
await msg.reply("❌ Ошибка при создании категории.", reply_markup=return_menu)
return
category = await categories_repo.add_category(
session, name=msg.text, parent_id=parse_cat_id(ctx.parent_id)
)
await ctx.msg.edit_text(
f"✅ Категория {msg.text} создана успешно.",
reply_markup=get_back_to_catalogue(category.id, text="🛒 Перейти"),
)

View File

@@ -26,15 +26,16 @@ async def subcatalogue(
view = await catalogue_service.build_category_view(session, cat_id)
kb = render_catalogue(view, is_admin=is_admin)
path = await catalogue_service.get_path(session, cat_id)
if cb.message.photo:
await cb.message.delete()
await cb.answer(
"category selection",
await cb.message.answer(
f"{path}",
reply_markup=kb,
)
return
await cb.message.edit_text(
"category selection",
f"{path}",
reply_markup=kb,
)

View File

@@ -1,7 +1,9 @@
import os
import logging
from re import Match
from aiogram import Router, F
from aiogram.types import CallbackQuery, FSInputFile
from aiogram.exceptions import TelegramBadRequest
from aiogram.fsm.context import FSMContext
from sqlalchemy.ext.asyncio import AsyncSession
@@ -17,6 +19,7 @@ from services.catalogue import CatalogueService
from services.orders import OrderService
router = Router()
logger = logging.getLogger(__name__)
@router.callback_query(
@@ -73,17 +76,9 @@ async def product_card(
cart_amount=order_item,
)
if product.file_id:
await cb.message.delete()
msg = await cb.message.answer_photo(
product.file_id,
caption=get_product_description(product),
reply_markup=kb,
)
return
if not os.path.isfile(product.img_path):
if not product.file_id and not (
product.img_path and os.path.isfile(product.img_path)
):
await cb.message.edit_text(
get_product_description(product),
reply_markup=kb,
@@ -91,6 +86,20 @@ async def product_card(
return
await cb.message.delete()
if product.file_id:
msg = await cb.message.answer_photo(
product.file_id,
caption=get_product_description(product),
reply_markup=kb,
)
return
try:
await cb.message.edit_text("<b>⏳ Загружаем карточку товара...</b>")
except TelegramBadRequest:
...
msg = await cb.message.answer_photo(
FSInputFile(product.img_path),
caption=get_product_description(product),
@@ -98,6 +107,7 @@ async def product_card(
)
if not msg.photo:
logger.warning("didnt get a photo back wahhh :(")
return # TODO: Add logging
await products_repo.add_product_file_id(