modify package and class name

This commit is contained in:
MaysWind
2021-04-18 00:00:50 +08:00
parent d5cb452c1f
commit bd9c8c7890
5 changed files with 48 additions and 48 deletions
+4 -4
View File
@@ -5,9 +5,9 @@ import (
"strings"
"time"
"github.com/mayswind/ezbookkeeping/pkg/converters"
"github.com/mayswind/ezbookkeeping/pkg/core"
"github.com/mayswind/ezbookkeeping/pkg/errs"
"github.com/mayswind/ezbookkeeping/pkg/exporters"
"github.com/mayswind/ezbookkeeping/pkg/log"
"github.com/mayswind/ezbookkeeping/pkg/models"
"github.com/mayswind/ezbookkeeping/pkg/services"
@@ -19,7 +19,7 @@ const pageCountForDataExport = 1000
// DataManagementsApi represents data management api
type DataManagementsApi struct {
exporter *exporters.CSVFileExporter
exporter *converters.EzBookKeepingCSVFileExporter
tokens *services.TokenService
users *services.UserService
accounts *services.AccountService
@@ -31,7 +31,7 @@ type DataManagementsApi struct {
// Initialize a data management api singleton instance
var (
DataManagements = &DataManagementsApi{
exporter: &exporters.CSVFileExporter{},
exporter: &converters.EzBookKeepingCSVFileExporter{},
tokens: services.Tokens,
users: services.Users,
accounts: services.Accounts,
@@ -97,7 +97,7 @@ func (a *DataManagementsApi) ExportDataHandler(c *core.Context) ([]byte, string,
return nil, "", errs.ErrOperationFailed
}
result, err := a.exporter.GetOutputContent(uid, timezone, allTransactions, accountMap, categoryMap, tagMap, tagIndexs)
result, err := a.exporter.ToExportedContent(uid, timezone, allTransactions, accountMap, categoryMap, tagMap, tagIndexs)
if err != nil {
log.ErrorfWithRequestId(c, "[data_managements.ExportDataHandler] failed to get csv format exported data for \"uid:%d\", because %s", uid, err.Error())
+18 -18
View File
@@ -5,8 +5,8 @@ import (
"github.com/urfave/cli/v2"
"github.com/mayswind/ezbookkeeping/pkg/converters"
"github.com/mayswind/ezbookkeeping/pkg/errs"
"github.com/mayswind/ezbookkeeping/pkg/exporters"
"github.com/mayswind/ezbookkeeping/pkg/log"
"github.com/mayswind/ezbookkeeping/pkg/models"
"github.com/mayswind/ezbookkeeping/pkg/services"
@@ -18,27 +18,27 @@ const pageCountForDataExport = 1000
// UserDataCli represents user data cli
type UserDataCli struct {
csvExporter *exporters.CSVFileExporter
accounts *services.AccountService
transactions *services.TransactionService
categories *services.TransactionCategoryService
tags *services.TransactionTagService
users *services.UserService
twoFactorAuthorizations *services.TwoFactorAuthorizationService
tokens *services.TokenService
ezBookKeepingCsvExporter *converters.EzBookKeepingCSVFileExporter
accounts *services.AccountService
transactions *services.TransactionService
categories *services.TransactionCategoryService
tags *services.TransactionTagService
users *services.UserService
twoFactorAuthorizations *services.TwoFactorAuthorizationService
tokens *services.TokenService
}
// Initialize an user data cli singleton instance
var (
UserData = &UserDataCli{
csvExporter: &exporters.CSVFileExporter{},
accounts: services.Accounts,
transactions: services.Transactions,
categories: services.TransactionCategories,
tags: services.TransactionTags,
users: services.Users,
twoFactorAuthorizations: services.TwoFactorAuthorizations,
tokens: services.Tokens,
ezBookKeepingCsvExporter: &converters.EzBookKeepingCSVFileExporter{},
accounts: services.Accounts,
transactions: services.Transactions,
categories: services.TransactionCategories,
tags: services.TransactionTags,
users: services.Users,
twoFactorAuthorizations: services.TwoFactorAuthorizations,
tokens: services.Tokens,
}
)
@@ -417,7 +417,7 @@ func (l *UserDataCli) ExportTransaction(c *cli.Context, username string) ([]byte
return nil, err
}
result, err := l.csvExporter.GetOutputContent(uid, time.Local, allTransactions, accountMap, categoryMap, tagMap, tagIndexs)
result, err := l.ezBookKeepingCsvExporter.ToExportedContent(uid, time.Local, allTransactions, accountMap, categoryMap, tagMap, tagIndexs)
if err != nil {
log.BootErrorf("[user_data.ExportTransaction] failed to get csv format exported data for \"%s\", because %s", username, err.Error())
+13
View File
@@ -0,0 +1,13 @@
package converters
import (
"time"
"github.com/mayswind/ezbookkeeping/pkg/models"
)
// DataConverter defines the structure of data exporter
type DataConverter interface {
// ToExportedContent returns the exported data
ToExportedContent(uid int64, timezone *time.Location, transactions []*models.Transaction, accountMap map[int64]*models.Account, categoryMap map[int64]*models.TransactionCategory, tagMap map[int64]*models.TransactionTag, allTagIndexs map[int64][]int64) ([]byte, error)
}
@@ -1,4 +1,4 @@
package exporters
package converters
import (
"fmt"
@@ -9,16 +9,16 @@ import (
"github.com/mayswind/ezbookkeeping/pkg/utils"
)
// CSVFileExporter defines the structure of csv file exporter
type CSVFileExporter struct {
DataExporter
// EzBookKeepingCSVFileExporter defines the structure of csv file exporter
type EzBookKeepingCSVFileExporter struct {
DataConverter
}
const csvHeaderLine = "Time,Type,Category,Sub Category,Account,Amount,Account2,Account2 Amount,Tags,Comment\n"
const csvDataLineFormat = "%s,%s,%s,%s,%s,%s,%s,%s,%s,%s\n"
// GetOutputContent returns the exported csv data
func (e *CSVFileExporter) GetOutputContent(uid int64, timezone *time.Location, transactions []*models.Transaction, accountMap map[int64]*models.Account, categoryMap map[int64]*models.TransactionCategory, tagMap map[int64]*models.TransactionTag, allTagIndexs map[int64][]int64) ([]byte, error) {
// ToExportedContent returns the exported csv data
func (e *EzBookKeepingCSVFileExporter) ToExportedContent(uid int64, timezone *time.Location, transactions []*models.Transaction, accountMap map[int64]*models.Account, categoryMap map[int64]*models.TransactionCategory, tagMap map[int64]*models.TransactionTag, allTagIndexs map[int64][]int64) ([]byte, error) {
var ret strings.Builder
ret.Grow(len(transactions) * 100)
@@ -55,7 +55,7 @@ func (e *CSVFileExporter) GetOutputContent(uid int64, timezone *time.Location, t
return []byte(ret.String()), nil
}
func (e *CSVFileExporter) getTransactionTypeName(transactionDbType models.TransactionDbType) string {
func (e *EzBookKeepingCSVFileExporter) getTransactionTypeName(transactionDbType models.TransactionDbType) string {
if transactionDbType == models.TRANSACTION_DB_TYPE_MODIFY_BALANCE {
return "Balance Modification"
} else if transactionDbType == models.TRANSACTION_DB_TYPE_INCOME {
@@ -69,7 +69,7 @@ func (e *CSVFileExporter) getTransactionTypeName(transactionDbType models.Transa
}
}
func (e *CSVFileExporter) getTransactionCategoryName(categoryId int64, categoryMap map[int64]*models.TransactionCategory) string {
func (e *EzBookKeepingCSVFileExporter) getTransactionCategoryName(categoryId int64, categoryMap map[int64]*models.TransactionCategory) string {
category, exists := categoryMap[categoryId]
if !exists {
@@ -89,7 +89,7 @@ func (e *CSVFileExporter) getTransactionCategoryName(categoryId int64, categoryM
return parentCategory.Name
}
func (e *CSVFileExporter) getTransactionSubCategoryName(categoryId int64, categoryMap map[int64]*models.TransactionCategory) string {
func (e *EzBookKeepingCSVFileExporter) getTransactionSubCategoryName(categoryId int64, categoryMap map[int64]*models.TransactionCategory) string {
category, exists := categoryMap[categoryId]
if exists {
@@ -99,7 +99,7 @@ func (e *CSVFileExporter) getTransactionSubCategoryName(categoryId int64, catego
}
}
func (e *CSVFileExporter) getAccountName(accountId int64, accountMap map[int64]*models.Account) string {
func (e *EzBookKeepingCSVFileExporter) getAccountName(accountId int64, accountMap map[int64]*models.Account) string {
account, exists := accountMap[accountId]
if exists {
@@ -109,7 +109,7 @@ func (e *CSVFileExporter) getAccountName(accountId int64, accountMap map[int64]*
}
}
func (e *CSVFileExporter) getDisplayAmount(amount int64) string {
func (e *EzBookKeepingCSVFileExporter) getDisplayAmount(amount int64) string {
displayAmount := utils.Int64ToString(amount)
integer := utils.SubString(displayAmount, 0, len(displayAmount)-2)
decimals := utils.SubString(displayAmount, -2, 2)
@@ -129,7 +129,7 @@ func (e *CSVFileExporter) getDisplayAmount(amount int64) string {
return integer + "." + decimals
}
func (e *CSVFileExporter) getTags(transactionId int64, allTagIndexs map[int64][]int64, tagMap map[int64]*models.TransactionTag) string {
func (e *EzBookKeepingCSVFileExporter) getTags(transactionId int64, allTagIndexs map[int64][]int64, tagMap map[int64]*models.TransactionTag) string {
tagIndexs, exists := allTagIndexs[transactionId]
if !exists {
@@ -156,7 +156,7 @@ func (e *CSVFileExporter) getTags(transactionId int64, allTagIndexs map[int64][]
return ret.String()
}
func (e *CSVFileExporter) getComment(comment string) string {
func (e *EzBookKeepingCSVFileExporter) getComment(comment string) string {
comment = strings.Replace(comment, ",", " ", -1)
comment = strings.Replace(comment, "\r\n", " ", -1)
comment = strings.Replace(comment, "\n", " ", -1)
-13
View File
@@ -1,13 +0,0 @@
package exporters
import (
"time"
"github.com/mayswind/ezbookkeeping/pkg/models"
)
// DataExporter defines the structure of data exporter
type DataExporter interface {
// GetOutputContent returns the exported data
GetOutputContent(uid int64, timezone *time.Location, transactions []*models.Transaction, accountMap map[int64]*models.Account, categoryMap map[int64]*models.TransactionCategory, tagMap map[int64]*models.TransactionTag, allTagIndexs map[int64][]int64) ([]byte, error)
}