added crud for categories entity

This commit is contained in:
Hosein
2026-01-05 11:55:58 +03:30
parent 7b6c2a3245
commit 8680778584
6 changed files with 338 additions and 5 deletions
+31
View File
@@ -0,0 +1,31 @@
import logging
from telebot import types
from database.models import Categories
logger = logging.getLogger(__name__)
def register(bot):
@bot.message_handler(func=lambda message: message.text == "Show Categories")
def get_categories(message):
try:
data = Categories.getAllCategories()
if data:
markup = types.InlineKeyboardMarkup(row_width=2)
for row in data:
btn = types.InlineKeyboardButton(
f"{row[1]} | id#{row[0]}", callback_data=f"category_{row[0]}")
markup.add(btn)
# add button for creating a new category
markup.add(types.InlineKeyboardButton(
" Create New Category", callback_data="create_category"))
bot.send_message(
message.chat.id, "Here is the data:", reply_markup=markup)
else:
bot.reply_to(message, "No data found.")
except Exception as e:
logger.error(f"Error in 'Show Categories' handler: {e}")
bot.reply_to(message, "Sorry, an error occurred.")
+2 -1
View File
@@ -1,4 +1,4 @@
from . import start, students, teachers, courses, tags, common
from . import start, students, teachers, courses, tags, categories, common
from bot.callbacks.init import register_all_callbacks
@@ -10,6 +10,7 @@ def register_all_handlers(bot):
teachers.register(bot)
courses.register(bot)
tags.register(bot)
categories.register(bot)
common.register(bot) # Must be last (catch-all)
# Callback handlers