Filter tasks categories in delegation menu #189

Merged
romanskijdev merged 1 commits from fix-permissions into main 2026-10-13 16:41:03 +03:00
2 changed files with 50 additions and 4 deletions

View File

@ -30,8 +30,49 @@ type ApprovalTopicExecutorDBI interface {
GetApprovalTopicExecutorListWithParamsDB(ctx context.Context, opts typescore.ListDbOptions) ([]*typescore.ApprovalTopicExecutor, uint64, error)
GetApprovalTopicExecutorListByCategoryDB(ctx context.Context, opts typescore.ListDbOptions, categoryID uint64) ([]*typescore.ApprovalTopicExecutor, uint64, error)
GetExecutorCategoriesDB(ctx context.Context, userID uint64) ([]*typescore.ApprovalTopicCategory, error)
GetExecutorTopicsByCategoryDB(ctx context.Context, userID uint64, categoryID uint64) ([]*typescore.ApprovalTopic, error)
}
func (d *ApprovalTopicExecutorDB) GetExecutorTopicsByCategoryDB(ctx context.Context, userID uint64, categoryID uint64) ([]*typescore.ApprovalTopic, error) {
fields := dbutils.GetStructFieldsDB(&typescore.ApprovalTopic{}, "t")
query := squirrel.StatementBuilder.PlaceholderFormat(squirrel.Dollar).
Select(fields...).
From(dbcoretablenames.TableNameApprovalTopicExecutor.ToString() + " ate").
Join(dbcoretablenames.TableNameApprovalTopics.ToString() + " t ON t.id = ate.topic_id").
Where(squirrel.Eq{
"ate.user_id": userID,
"ate.is_active": true,
"t.category_id": categoryID,
"t.is_active": true,
}).
GroupBy("t.id").
OrderBy("t.name ASC")
sql, args, err := query.ToSql()
if err != nil {
return nil, err
}
rows, err := d.pool.Query(ctx, sql, args...)
if err != nil {
logrus.Errorf("GetExecutorTopicsByCategoryDB Query error: %v", err)
return nil, err
}
defer rows.Close()
var topics []*typescore.ApprovalTopic
for rows.Next() {
topic := &typescore.ApprovalTopic{}
if err := dbutils.ScanRowsToStructRows(rows, topic, nil); err != nil {
logrus.Warn("GetExecutorTopicsByCategoryDB:ScanRowsToStructRows", err)
continue
}
topics = append(topics, topic)
}
return topics, nil
}
func (d *ApprovalTopicExecutorDB) GetExecutorCategoriesDB(ctx context.Context, userID uint64) ([]*typescore.ApprovalTopicCategory, error) {
fields := dbutils.GetStructFieldsDB(&typescore.ApprovalTopicCategory{}, "c")

View File

@ -276,20 +276,25 @@ func (h *Handler) HandleTaskDelegationCategoryCallback(bot *tgbotapi.BotAPI, cq
func (h *Handler) HandleTaskDelegationCategoryCallbackPage(bot *tgbotapi.BotAPI, cq *tgbotapi.CallbackQuery, categoryID uint64, page int) {
ctx := context.Background()
chatID := cq.Message.Chat.ID
telegramID := cq.From.ID
bot.Request(tgbotapi.NewCallback(cq.ID, "")) //nolint:errcheck
bot.Request(tgbotapi.NewDeleteMessage(chatID, cq.Message.MessageID)) //nolint:errcheck
user, err := h.ipc.Database.User.GetUserByTelegramIDDB(ctx, telegramID)
if err != nil || user == nil || user.ID == nil {
return
}
category, _ := h.ipc.Database.ApprovalTopicCategory.GetApprovalTopicCategoryByIDDB(ctx, categoryID)
categoryName := "—"
if category != nil && category.Name != nil {
categoryName = *category.Name
}
topics, _, err := h.ipc.Database.ApprovalTopic.GetApprovalTopicsListDB(ctx, typescore.ListDbOptions{
Filtering: &typescore.ApprovalTopic{CategoryID: &categoryID},
})
if err != nil {
topics, err := h.ipc.Database.ApprovalTopicExecutor.GetExecutorTopicsByCategoryDB(ctx, *user.ID, categoryID)
if err != nil || len(topics) == 0 {
sendText(bot, chatID, "В этой категории нет доступных вам тем с задачами.")
return
}