catalogue operations, db migr and so on.
pre release version.
This commit is contained in:
70
handlers/admins/creation.py
Normal file
70
handlers/admins/creation.py
Normal 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="🛒 Перейти"),
|
||||
)
|
||||
Reference in New Issue
Block a user