diff --git a/pkg/api/accounts.go b/pkg/api/accounts.go index ed823a7f..700196fe 100644 --- a/pkg/api/accounts.go +++ b/pkg/api/accounts.go @@ -212,7 +212,7 @@ func (a *AccountsApi) AccountCreateHandler(c *core.Context) (any, *errs.Error) { childrenAccounts := a.createSubAccountModels(uid, &accountCreateReq) if settings.Container.Current.EnableDuplicateSubmissionsCheck && accountCreateReq.ClientSessionId != "" { - found, remark := duplicatechecker.Container.Get(duplicatechecker.DUPLICATE_CHECKER_TYPE_NEW_ACCOUNT, uid, accountCreateReq.ClientSessionId) + found, remark := duplicatechecker.Container.GetSubmissionRemark(duplicatechecker.DUPLICATE_CHECKER_TYPE_NEW_ACCOUNT, uid, accountCreateReq.ClientSessionId) if found { log.InfofWithRequestId(c, "[accounts.AccountCreateHandler] another account \"id:%s\" has been created for user \"uid:%d\"", remark, uid) @@ -256,7 +256,7 @@ func (a *AccountsApi) AccountCreateHandler(c *core.Context) (any, *errs.Error) { log.InfofWithRequestId(c, "[accounts.AccountCreateHandler] user \"uid:%d\" has created a new account \"id:%d\" successfully", uid, mainAccount.AccountId) - duplicatechecker.Container.Set(duplicatechecker.DUPLICATE_CHECKER_TYPE_NEW_ACCOUNT, uid, accountCreateReq.ClientSessionId, utils.Int64ToString(mainAccount.AccountId)) + duplicatechecker.Container.SetSubmissionRemark(duplicatechecker.DUPLICATE_CHECKER_TYPE_NEW_ACCOUNT, uid, accountCreateReq.ClientSessionId, utils.Int64ToString(mainAccount.AccountId)) accountInfoResp := mainAccount.ToAccountInfoResponse() if len(childrenAccounts) > 0 { diff --git a/pkg/api/transaction_categories.go b/pkg/api/transaction_categories.go index 9631d735..7b039248 100644 --- a/pkg/api/transaction_categories.go +++ b/pkg/api/transaction_categories.go @@ -123,7 +123,7 @@ func (a *TransactionCategoriesApi) CategoryCreateHandler(c *core.Context) (any, category := a.createNewCategoryModel(uid, &categoryCreateReq, maxOrderId+1) if settings.Container.Current.EnableDuplicateSubmissionsCheck && categoryCreateReq.ClientSessionId != "" { - found, remark := duplicatechecker.Container.Get(duplicatechecker.DUPLICATE_CHECKER_TYPE_NEW_CATEGORY, uid, categoryCreateReq.ClientSessionId) + found, remark := duplicatechecker.Container.GetSubmissionRemark(duplicatechecker.DUPLICATE_CHECKER_TYPE_NEW_CATEGORY, uid, categoryCreateReq.ClientSessionId) if found { log.InfofWithRequestId(c, "[transaction_categories.CategoryCreateHandler] another category \"id:%s\" has been created for user \"uid:%d\"", remark, uid) @@ -153,7 +153,7 @@ func (a *TransactionCategoriesApi) CategoryCreateHandler(c *core.Context) (any, log.InfofWithRequestId(c, "[transaction_categories.CategoryCreateHandler] user \"uid:%d\" has created a new category \"id:%d\" successfully", uid, category.CategoryId) - duplicatechecker.Container.Set(duplicatechecker.DUPLICATE_CHECKER_TYPE_NEW_CATEGORY, uid, categoryCreateReq.ClientSessionId, utils.Int64ToString(category.CategoryId)) + duplicatechecker.Container.SetSubmissionRemark(duplicatechecker.DUPLICATE_CHECKER_TYPE_NEW_CATEGORY, uid, categoryCreateReq.ClientSessionId, utils.Int64ToString(category.CategoryId)) categoryResp := category.ToTransactionCategoryInfoResponse() return categoryResp, nil diff --git a/pkg/api/transaction_templates.go b/pkg/api/transaction_templates.go index 1869f45b..ba6124f8 100644 --- a/pkg/api/transaction_templates.go +++ b/pkg/api/transaction_templates.go @@ -118,7 +118,7 @@ func (a *TransactionTemplatesApi) TemplateCreateHandler(c *core.Context) (any, * template := a.createNewTemplateModel(uid, &templateCreateReq, maxOrderId+1) if settings.Container.Current.EnableDuplicateSubmissionsCheck && templateCreateReq.ClientSessionId != "" { - found, remark := duplicatechecker.Container.Get(duplicatechecker.DUPLICATE_CHECKER_TYPE_NEW_TEMPLATE, uid, templateCreateReq.ClientSessionId) + found, remark := duplicatechecker.Container.GetSubmissionRemark(duplicatechecker.DUPLICATE_CHECKER_TYPE_NEW_TEMPLATE, uid, templateCreateReq.ClientSessionId) if found { log.InfofWithRequestId(c, "[transaction_templates.TemplateCreateHandler] another template \"id:%s\" has been created for user \"uid:%d\"", remark, uid) @@ -148,7 +148,7 @@ func (a *TransactionTemplatesApi) TemplateCreateHandler(c *core.Context) (any, * log.InfofWithRequestId(c, "[transaction_templates.TemplateCreateHandler] user \"uid:%d\" has created a new template \"id:%d\" successfully", uid, template.TemplateId) - duplicatechecker.Container.Set(duplicatechecker.DUPLICATE_CHECKER_TYPE_NEW_TEMPLATE, uid, templateCreateReq.ClientSessionId, utils.Int64ToString(template.TemplateId)) + duplicatechecker.Container.SetSubmissionRemark(duplicatechecker.DUPLICATE_CHECKER_TYPE_NEW_TEMPLATE, uid, templateCreateReq.ClientSessionId, utils.Int64ToString(template.TemplateId)) templateResp := template.ToTransactionTemplateInfoResponse(serverUtcOffset) return templateResp, nil diff --git a/pkg/api/transactions.go b/pkg/api/transactions.go index 1939cd16..8dff5579 100644 --- a/pkg/api/transactions.go +++ b/pkg/api/transactions.go @@ -664,7 +664,7 @@ func (a *TransactionsApi) TransactionCreateHandler(c *core.Context) (any, *errs. } if settings.Container.Current.EnableDuplicateSubmissionsCheck && transactionCreateReq.ClientSessionId != "" { - found, remark := duplicatechecker.Container.Get(duplicatechecker.DUPLICATE_CHECKER_TYPE_NEW_TRANSACTION, uid, transactionCreateReq.ClientSessionId) + found, remark := duplicatechecker.Container.GetSubmissionRemark(duplicatechecker.DUPLICATE_CHECKER_TYPE_NEW_TRANSACTION, uid, transactionCreateReq.ClientSessionId) if found { log.InfofWithRequestId(c, "[transactions.TransactionCreateHandler] another transaction \"id:%s\" has been created for user \"uid:%d\"", remark, uid) @@ -694,7 +694,7 @@ func (a *TransactionsApi) TransactionCreateHandler(c *core.Context) (any, *errs. log.InfofWithRequestId(c, "[transactions.TransactionCreateHandler] user \"uid:%d\" has created a new transaction \"id:%d\" successfully", uid, transaction.TransactionId) - duplicatechecker.Container.Set(duplicatechecker.DUPLICATE_CHECKER_TYPE_NEW_TRANSACTION, uid, transactionCreateReq.ClientSessionId, utils.Int64ToString(transaction.TransactionId)) + duplicatechecker.Container.SetSubmissionRemark(duplicatechecker.DUPLICATE_CHECKER_TYPE_NEW_TRANSACTION, uid, transactionCreateReq.ClientSessionId, utils.Int64ToString(transaction.TransactionId)) transactionResp := transaction.ToTransactionInfoResponse(tagIds, transactionEditable) return transactionResp, nil diff --git a/pkg/duplicatechecker/duplicate_checker.go b/pkg/duplicatechecker/duplicate_checker.go index f9c5b760..999b3a04 100644 --- a/pkg/duplicatechecker/duplicate_checker.go +++ b/pkg/duplicatechecker/duplicate_checker.go @@ -2,6 +2,6 @@ package duplicatechecker // DuplicateChecker is common duplicate checker interface type DuplicateChecker interface { - Get(checkerType DuplicateCheckerType, uid int64, identification string) (bool, string) - Set(checkerType DuplicateCheckerType, uid int64, identification string, remark string) + GetSubmissionRemark(checkerType DuplicateCheckerType, uid int64, identification string) (bool, string) + SetSubmissionRemark(checkerType DuplicateCheckerType, uid int64, identification string, remark string) } diff --git a/pkg/duplicatechecker/duplicate_checker_container.go b/pkg/duplicatechecker/duplicate_checker_container.go index 8634b0e8..8dd553c2 100644 --- a/pkg/duplicatechecker/duplicate_checker_container.go +++ b/pkg/duplicatechecker/duplicate_checker_container.go @@ -27,12 +27,12 @@ func InitializeDuplicateChecker(config *settings.Config) error { return errs.ErrInvalidDuplicateCheckerType } -// Get returns whether the same submission has been processed and related remark by the current duplicate checker -func (c *DuplicateCheckerContainer) Get(checkerType DuplicateCheckerType, uid int64, identification string) (bool, string) { - return c.Current.Get(checkerType, uid, identification) +// GetSubmissionRemark returns whether the same submission has been processed and related remark by the current duplicate checker +func (c *DuplicateCheckerContainer) GetSubmissionRemark(checkerType DuplicateCheckerType, uid int64, identification string) (bool, string) { + return c.Current.GetSubmissionRemark(checkerType, uid, identification) } -// Set saves the identification and remark to in-memory cache by the current duplicate checker -func (c *DuplicateCheckerContainer) Set(checkerType DuplicateCheckerType, uid int64, identification string, remark string) { - c.Current.Set(checkerType, uid, identification, remark) +// SetSubmissionRemark saves the identification and remark to in-memory cache by the current duplicate checker +func (c *DuplicateCheckerContainer) SetSubmissionRemark(checkerType DuplicateCheckerType, uid int64, identification string, remark string) { + c.Current.SetSubmissionRemark(checkerType, uid, identification, remark) } diff --git a/pkg/duplicatechecker/in_memory_duplicate_checker.go b/pkg/duplicatechecker/in_memory_duplicate_checker.go index 7207da83..3b619923 100644 --- a/pkg/duplicatechecker/in_memory_duplicate_checker.go +++ b/pkg/duplicatechecker/in_memory_duplicate_checker.go @@ -22,8 +22,8 @@ func NewInMemoryDuplicateChecker(config *settings.Config) (*InMemoryDuplicateChe return checker, nil } -// Get returns whether the same submission has been processed and related remark -func (c *InMemoryDuplicateChecker) Get(checkerType DuplicateCheckerType, uid int64, identification string) (bool, string) { +// GetSubmissionRemark returns whether the same submission has been processed and related remark +func (c *InMemoryDuplicateChecker) GetSubmissionRemark(checkerType DuplicateCheckerType, uid int64, identification string) (bool, string) { existedRemark, found := c.cache.Get(c.getCacheKey(checkerType, uid, identification)) if found { @@ -33,8 +33,8 @@ func (c *InMemoryDuplicateChecker) Get(checkerType DuplicateCheckerType, uid int return false, "" } -// Set saves the identification and remark to in-memory cache -func (c *InMemoryDuplicateChecker) Set(checkerType DuplicateCheckerType, uid int64, identification string, remark string) { +// SetSubmissionRemark saves the identification and remark to in-memory cache +func (c *InMemoryDuplicateChecker) SetSubmissionRemark(checkerType DuplicateCheckerType, uid int64, identification string, remark string) { c.cache.Set(c.getCacheKey(checkerType, uid, identification), remark, cache.DefaultExpiration) }