From 70beb45c4e58d80408f2e4085c67e73e9987cd01 Mon Sep 17 00:00:00 2001 From: MaysWind Date: Tue, 10 Sep 2024 00:23:31 +0800 Subject: [PATCH] add logs --- pkg/cli/user_data.go | 10 +++++++--- pkg/services/accounts.go | 11 +++++++++++ pkg/services/transaction_categories.go | 11 +++++++++++ pkg/services/transaction_tags.go | 11 +++++++++++ 4 files changed, 40 insertions(+), 3 deletions(-) diff --git a/pkg/cli/user_data.go b/pkg/cli/user_data.go index 60703009..4fa52a35 100644 --- a/pkg/cli/user_data.go +++ b/pkg/cli/user_data.go @@ -1,6 +1,7 @@ package cli import ( + "strings" "time" "github.com/mayswind/ezbookkeeping/pkg/converters" @@ -706,17 +707,20 @@ func (l *UserDataCli) ImportTransaction(c *core.CliContext, username string, fil } if len(newAccounts) > 0 { - log.BootErrorf(c, "[user_data.ImportTransaction] there are %d accounts need to be created, please create them manually", len(newAccounts)) + accountNames := l.accounts.GetAccountNames(newAccounts) + log.BootErrorf(c, "[user_data.ImportTransaction] there are %d accounts (%s) need to be created, please create them manually", len(newAccounts), strings.Join(accountNames, ",")) return errs.ErrOperationFailed } if len(newCategories) > 0 { - log.BootErrorf(c, "[user_data.ImportTransaction] there are %d transaction categories need to be created, please create them manually", len(newCategories)) + categoryNames := l.categories.GetCategoryNames(newCategories) + log.BootErrorf(c, "[user_data.ImportTransaction] there are %d transaction categories (%s) need to be created, please create them manually", len(newCategories), strings.Join(categoryNames, ",")) return errs.ErrOperationFailed } if len(newTags) > 0 { - log.BootErrorf(c, "[user_data.ImportTransaction] there are %d transaction tags need to be created, please create them manually", len(newTags)) + tagNames := l.tags.GetTagNames(newTags) + log.BootErrorf(c, "[user_data.ImportTransaction] there are %d transaction tags (%s) need to be created, please create them manually", len(newTags), strings.Join(tagNames, ",")) return errs.ErrOperationFailed } diff --git a/pkg/services/accounts.go b/pkg/services/accounts.go index ff64e02b..9a976d1c 100644 --- a/pkg/services/accounts.go +++ b/pkg/services/accounts.go @@ -474,3 +474,14 @@ func (s *AccountService) GetAccountNameMapByList(accounts []*models.Account) map } return accountMap } + +// GetAccountNames returns a list with account names from account models list +func (s *AccountService) GetAccountNames(accounts []*models.Account) []string { + accountNames := make([]string, len(accounts)) + + for i := 0; i < len(accounts); i++ { + accountNames[i] = accounts[i].Name + } + + return accountNames +} diff --git a/pkg/services/transaction_categories.go b/pkg/services/transaction_categories.go index fdd2faf8..be1e0e58 100644 --- a/pkg/services/transaction_categories.go +++ b/pkg/services/transaction_categories.go @@ -458,3 +458,14 @@ func (s *TransactionCategoryService) GetCategoryNameMapByList(categories []*mode } return categoryMap } + +// GetCategoryNames returns a list with transaction category names from transaction category models list +func (s *TransactionCategoryService) GetCategoryNames(categories []*models.TransactionCategory) []string { + categoryNames := make([]string, len(categories)) + + for i := 0; i < len(categories); i++ { + categoryNames[i] = categories[i].Name + } + + return categoryNames +} diff --git a/pkg/services/transaction_tags.go b/pkg/services/transaction_tags.go index baf8da0b..5a753af3 100644 --- a/pkg/services/transaction_tags.go +++ b/pkg/services/transaction_tags.go @@ -426,6 +426,17 @@ func (s *TransactionTagService) GetTagNameMapByList(tags []*models.TransactionTa return tagMap } +// GetTagNames returns a list with tag names from tag models list +func (s *TransactionTagService) GetTagNames(tags []*models.TransactionTag) []string { + tagNames := make([]string, len(tags)) + + for i := 0; i < len(tags); i++ { + tagNames[i] = tags[i].Name + } + + return tagNames +} + func (s *TransactionTagService) GetGroupedTransactionTagIds(tagIndexes []*models.TransactionTagIndex) map[int64][]int64 { allTransactionTagIds := make(map[int64][]int64)