Filter tasks categories in delegation menu #188

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

View File

@ -29,6 +29,48 @@ type ApprovalTopicExecutorDBI interface {
GetExecutorsByTopicIDDB(ctx context.Context, topicID uint64) ([]*typescore.ApprovalTopicExecutor, error)
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)
}
func (d *ApprovalTopicExecutorDB) GetExecutorCategoriesDB(ctx context.Context, userID uint64) ([]*typescore.ApprovalTopicCategory, error) {
fields := dbutils.GetStructFieldsDB(&typescore.ApprovalTopicCategory{}, "c")
query := squirrel.StatementBuilder.PlaceholderFormat(squirrel.Dollar).
Select(fields...).
From(dbcoretablenames.TableNameApprovalTopicExecutor.ToString() + " ate").
Join(dbcoretablenames.TableNameApprovalTopics.ToString() + " t ON t.id = ate.topic_id").
Join(dbcoretablenames.TableNameApprovalTopicCategories.ToString() + " c ON c.id = t.category_id").
Where(squirrel.Eq{
"ate.user_id": userID,
"ate.is_active": true,
"c.is_active": true,
}).
GroupBy("c.id").
OrderBy("c.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("GetExecutorCategoriesDB Query error: %v", err)
return nil, err
}
defer rows.Close()
var categories []*typescore.ApprovalTopicCategory
for rows.Next() {
cat := &typescore.ApprovalTopicCategory{}
if err := dbutils.ScanRowsToStructRows(rows, cat, nil); err != nil {
logrus.Warn("GetExecutorCategoriesDB:ScanRowsToStructRows", err)
continue
}
categories = append(categories, cat)
}
return categories, nil
}
func (d *ApprovalTopicExecutorDB) GetApprovalTopicExecutorListByCategoryDB(ctx context.Context, opts typescore.ListDbOptions, categoryID uint64) ([]*typescore.ApprovalTopicExecutor, uint64, error) {

View File

@ -248,7 +248,7 @@ func (h *Handler) HandleTaskDelegationMenuPage(bot *tgbotapi.BotAPI, chatID int6
return
}
categories, err := h.getExecutorCategories(ctx, *user.ID)
categories, err := h.ipc.Database.ApprovalTopicExecutor.GetExecutorCategoriesDB(ctx, *user.ID)
if err != nil || len(categories) == 0 {
sendText(bot, chatID, "У вас нет категорий с настроенными задачами для делегирования.")
return