code refactor
This commit is contained in:
+140
-141
@@ -3,9 +3,8 @@ package cli
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
|
||||
"github.com/mayswind/ezbookkeeping/pkg/converters"
|
||||
"github.com/mayswind/ezbookkeeping/pkg/core"
|
||||
"github.com/mayswind/ezbookkeeping/pkg/errs"
|
||||
"github.com/mayswind/ezbookkeeping/pkg/log"
|
||||
"github.com/mayswind/ezbookkeeping/pkg/models"
|
||||
@@ -52,34 +51,34 @@ var (
|
||||
)
|
||||
|
||||
// AddNewUser adds a new user according to specified info
|
||||
func (l *UserDataCli) AddNewUser(c *cli.Context, username string, email string, nickname string, password string, defaultCurrency string) (*models.User, error) {
|
||||
func (l *UserDataCli) AddNewUser(c *core.CliContext, username string, email string, nickname string, password string, defaultCurrency string) (*models.User, error) {
|
||||
if username == "" {
|
||||
log.BootErrorf("[user_data.AddNewUser] user name is empty")
|
||||
log.BootErrorf(c, "[user_data.AddNewUser] user name is empty")
|
||||
return nil, errs.ErrUsernameIsEmpty
|
||||
}
|
||||
|
||||
if email == "" {
|
||||
log.BootErrorf("[user_data.AddNewUser] user email is empty")
|
||||
log.BootErrorf(c, "[user_data.AddNewUser] user email is empty")
|
||||
return nil, errs.ErrEmailIsEmpty
|
||||
}
|
||||
|
||||
if nickname == "" {
|
||||
log.BootErrorf("[user_data.AddNewUser] user nickname is empty")
|
||||
log.BootErrorf(c, "[user_data.AddNewUser] user nickname is empty")
|
||||
return nil, errs.ErrNicknameIsEmpty
|
||||
}
|
||||
|
||||
if password == "" {
|
||||
log.BootErrorf("[user_data.AddNewUser] user password is empty")
|
||||
log.BootErrorf(c, "[user_data.AddNewUser] user password is empty")
|
||||
return nil, errs.ErrPasswordIsEmpty
|
||||
}
|
||||
|
||||
if defaultCurrency == "" {
|
||||
log.BootErrorf("[user_data.AddNewUser] user default currency is empty")
|
||||
log.BootErrorf(c, "[user_data.AddNewUser] user default currency is empty")
|
||||
return nil, errs.ErrUserDefaultCurrencyIsEmpty
|
||||
}
|
||||
|
||||
if _, ok := validators.AllCurrencyNames[defaultCurrency]; !ok {
|
||||
log.BootErrorf("[user_data.AddNewUser] user default currency is invalid")
|
||||
log.BootErrorf(c, "[user_data.AddNewUser] user default currency is invalid")
|
||||
return nil, errs.ErrUserDefaultCurrencyIsInvalid
|
||||
}
|
||||
|
||||
@@ -93,29 +92,29 @@ func (l *UserDataCli) AddNewUser(c *cli.Context, username string, email string,
|
||||
TransactionEditScope: models.TRANSACTION_EDIT_SCOPE_ALL,
|
||||
}
|
||||
|
||||
err := l.users.CreateUser(nil, user)
|
||||
err := l.users.CreateUser(c, user)
|
||||
|
||||
if err != nil {
|
||||
log.BootErrorf("[user_data.AddNewUser] failed to create user \"%s\", because %s", user.Username, err.Error())
|
||||
log.BootErrorf(c, "[user_data.AddNewUser] failed to create user \"%s\", because %s", user.Username, err.Error())
|
||||
return nil, err
|
||||
}
|
||||
|
||||
log.BootInfof("[user_data.AddNewUser] user \"%s\" has add successfully, uid is %d", user.Username, user.Uid)
|
||||
log.BootInfof(c, "[user_data.AddNewUser] user \"%s\" has add successfully, uid is %d", user.Username, user.Uid)
|
||||
|
||||
return user, nil
|
||||
}
|
||||
|
||||
// GetUserByUsername returns user by user name
|
||||
func (l *UserDataCli) GetUserByUsername(c *cli.Context, username string) (*models.User, error) {
|
||||
func (l *UserDataCli) GetUserByUsername(c *core.CliContext, username string) (*models.User, error) {
|
||||
if username == "" {
|
||||
log.BootErrorf("[user_data.GetUserByUsername] user name is empty")
|
||||
log.BootErrorf(c, "[user_data.GetUserByUsername] user name is empty")
|
||||
return nil, errs.ErrUsernameIsEmpty
|
||||
}
|
||||
|
||||
user, err := l.users.GetUserByUsername(nil, username)
|
||||
user, err := l.users.GetUserByUsername(c, username)
|
||||
|
||||
if err != nil {
|
||||
log.BootErrorf("[user_data.GetUserByUsername] failed to get user by user name \"%s\", because %s", username, err.Error())
|
||||
log.BootErrorf(c, "[user_data.GetUserByUsername] failed to get user by user name \"%s\", because %s", username, err.Error())
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -123,21 +122,21 @@ func (l *UserDataCli) GetUserByUsername(c *cli.Context, username string) (*model
|
||||
}
|
||||
|
||||
// ModifyUserPassword modifies user password
|
||||
func (l *UserDataCli) ModifyUserPassword(c *cli.Context, username string, password string) error {
|
||||
func (l *UserDataCli) ModifyUserPassword(c *core.CliContext, username string, password string) error {
|
||||
if username == "" {
|
||||
log.BootErrorf("[user_data.ModifyUserPassword] user name is empty")
|
||||
log.BootErrorf(c, "[user_data.ModifyUserPassword] user name is empty")
|
||||
return errs.ErrUsernameIsEmpty
|
||||
}
|
||||
|
||||
if password == "" {
|
||||
log.BootErrorf("[user_data.ModifyUserPassword] user password is empty")
|
||||
log.BootErrorf(c, "[user_data.ModifyUserPassword] user password is empty")
|
||||
return errs.ErrPasswordIsEmpty
|
||||
}
|
||||
|
||||
user, err := l.users.GetUserByUsername(nil, username)
|
||||
user, err := l.users.GetUserByUsername(c, username)
|
||||
|
||||
if err != nil {
|
||||
log.BootErrorf("[user_data.ModifyUserPassword] failed to get user by user name \"%s\", because %s", username, err.Error())
|
||||
log.BootErrorf(c, "[user_data.ModifyUserPassword] failed to get user by user name \"%s\", because %s", username, err.Error())
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -151,55 +150,55 @@ func (l *UserDataCli) ModifyUserPassword(c *cli.Context, username string, passwo
|
||||
Password: password,
|
||||
}
|
||||
|
||||
_, _, err = l.users.UpdateUser(nil, userNew, false)
|
||||
_, _, err = l.users.UpdateUser(c, userNew, false)
|
||||
|
||||
if err != nil {
|
||||
log.BootErrorf("[user_data.ModifyUserPassword] failed to update user \"%s\" password, because %s", user.Username, err.Error())
|
||||
log.BootErrorf(c, "[user_data.ModifyUserPassword] failed to update user \"%s\" password, because %s", user.Username, err.Error())
|
||||
return err
|
||||
}
|
||||
|
||||
now := time.Now().Unix()
|
||||
err = l.tokens.DeleteTokensBeforeTime(nil, user.Uid, now)
|
||||
err = l.tokens.DeleteTokensBeforeTime(c, user.Uid, now)
|
||||
|
||||
if err == nil {
|
||||
log.BootInfof("[user_data.ModifyUserPassword] revoke old tokens before unix time \"%d\" for user \"%s\"", now, user.Username)
|
||||
log.BootInfof(c, "[user_data.ModifyUserPassword] revoke old tokens before unix time \"%d\" for user \"%s\"", now, user.Username)
|
||||
} else {
|
||||
log.BootWarnf("[user_data.ModifyUserPassword] failed to revoke old tokens for user \"%s\", because %s", user.Username, err.Error())
|
||||
log.BootWarnf(c, "[user_data.ModifyUserPassword] failed to revoke old tokens for user \"%s\", because %s", user.Username, err.Error())
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// SendPasswordResetMail sends an email with password reset link
|
||||
func (l *UserDataCli) SendPasswordResetMail(c *cli.Context, username string) error {
|
||||
func (l *UserDataCli) SendPasswordResetMail(c *core.CliContext, username string) error {
|
||||
if username == "" {
|
||||
log.BootErrorf("[user_data.SendPasswordResetMail] user name is empty")
|
||||
log.BootErrorf(c, "[user_data.SendPasswordResetMail] user name is empty")
|
||||
return errs.ErrUsernameIsEmpty
|
||||
}
|
||||
|
||||
user, err := l.users.GetUserByUsername(nil, username)
|
||||
user, err := l.users.GetUserByUsername(c, username)
|
||||
|
||||
if err != nil {
|
||||
log.BootErrorf("[user_data.SendPasswordResetMail] failed to get user by user name \"%s\", because %s", username, err.Error())
|
||||
log.BootErrorf(c, "[user_data.SendPasswordResetMail] failed to get user by user name \"%s\", because %s", username, err.Error())
|
||||
return err
|
||||
}
|
||||
|
||||
if l.CurrentConfig().ForgetPasswordRequireVerifyEmail && !user.EmailVerified {
|
||||
log.BootWarnf("[user_data.SendPasswordResetMail] user \"uid:%d\" has not verified email", user.Uid)
|
||||
log.BootWarnf(c, "[user_data.SendPasswordResetMail] user \"uid:%d\" has not verified email", user.Uid)
|
||||
return errs.ErrEmailIsNotVerified
|
||||
}
|
||||
|
||||
token, _, err := l.tokens.CreatePasswordResetToken(nil, user)
|
||||
token, _, err := l.tokens.CreatePasswordResetTokenWithoutUserAgent(c, user)
|
||||
|
||||
if err != nil {
|
||||
log.BootErrorf("[user_data.SendPasswordResetMail] failed to create token for user \"uid:%d\", because %s", user.Uid, err.Error())
|
||||
log.BootErrorf(c, "[user_data.SendPasswordResetMail] failed to create token for user \"uid:%d\", because %s", user.Uid, err.Error())
|
||||
return err
|
||||
}
|
||||
|
||||
err = l.forgetPasswords.SendPasswordResetEmail(nil, user, token, "")
|
||||
err = l.forgetPasswords.SendPasswordResetEmail(c, user, token, "")
|
||||
|
||||
if err != nil {
|
||||
log.BootWarnf("[user_data.SendPasswordResetMail] cannot send email to \"%s\", because %s", user.Email, err.Error())
|
||||
log.BootWarnf(c, "[user_data.SendPasswordResetMail] cannot send email to \"%s\", because %s", user.Email, err.Error())
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -207,16 +206,16 @@ func (l *UserDataCli) SendPasswordResetMail(c *cli.Context, username string) err
|
||||
}
|
||||
|
||||
// EnableUser sets user enabled according to the specified user name
|
||||
func (l *UserDataCli) EnableUser(c *cli.Context, username string) error {
|
||||
func (l *UserDataCli) EnableUser(c *core.CliContext, username string) error {
|
||||
if username == "" {
|
||||
log.BootErrorf("[user_data.EnableUser] user name is empty")
|
||||
log.BootErrorf(c, "[user_data.EnableUser] user name is empty")
|
||||
return errs.ErrUsernameIsEmpty
|
||||
}
|
||||
|
||||
err := l.users.EnableUser(nil, username)
|
||||
err := l.users.EnableUser(c, username)
|
||||
|
||||
if err != nil {
|
||||
log.BootErrorf("[user_data.EnableUser] failed to set user enabled by user name \"%s\", because %s", username, err.Error())
|
||||
log.BootErrorf(c, "[user_data.EnableUser] failed to set user enabled by user name \"%s\", because %s", username, err.Error())
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -224,16 +223,16 @@ func (l *UserDataCli) EnableUser(c *cli.Context, username string) error {
|
||||
}
|
||||
|
||||
// DisableUser sets user disabled according to the specified user name
|
||||
func (l *UserDataCli) DisableUser(c *cli.Context, username string) error {
|
||||
func (l *UserDataCli) DisableUser(c *core.CliContext, username string) error {
|
||||
if username == "" {
|
||||
log.BootErrorf("[user_data.DisableUser] user name is empty")
|
||||
log.BootErrorf(c, "[user_data.DisableUser] user name is empty")
|
||||
return errs.ErrUsernameIsEmpty
|
||||
}
|
||||
|
||||
err := l.users.DisableUser(nil, username)
|
||||
err := l.users.DisableUser(c, username)
|
||||
|
||||
if err != nil {
|
||||
log.BootErrorf("[user_data.DisableUser] failed to set user disabled by user name \"%s\", because %s", username, err.Error())
|
||||
log.BootErrorf(c, "[user_data.DisableUser] failed to set user disabled by user name \"%s\", because %s", username, err.Error())
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -241,39 +240,39 @@ func (l *UserDataCli) DisableUser(c *cli.Context, username string) error {
|
||||
}
|
||||
|
||||
// ResendVerifyEmail resends an email with account activation link
|
||||
func (l *UserDataCli) ResendVerifyEmail(c *cli.Context, username string) error {
|
||||
func (l *UserDataCli) ResendVerifyEmail(c *core.CliContext, username string) error {
|
||||
if !l.CurrentConfig().EnableUserVerifyEmail {
|
||||
return errs.ErrEmailValidationNotAllowed
|
||||
}
|
||||
|
||||
if username == "" {
|
||||
log.BootErrorf("[user_data.ResendVerifyEmail] user name is empty")
|
||||
log.BootErrorf(c, "[user_data.ResendVerifyEmail] user name is empty")
|
||||
return errs.ErrUsernameIsEmpty
|
||||
}
|
||||
|
||||
user, err := l.users.GetUserByUsername(nil, username)
|
||||
user, err := l.users.GetUserByUsername(c, username)
|
||||
|
||||
if err != nil {
|
||||
log.BootErrorf("[user_data.ResendVerifyEmail] failed to get user by user name \"%s\", because %s", username, err.Error())
|
||||
log.BootErrorf(c, "[user_data.ResendVerifyEmail] failed to get user by user name \"%s\", because %s", username, err.Error())
|
||||
return err
|
||||
}
|
||||
|
||||
if user.EmailVerified {
|
||||
log.BootWarnf("[user_data.ResendVerifyEmail] user \"uid:%d\" email has been verified", user.Uid)
|
||||
log.BootWarnf(c, "[user_data.ResendVerifyEmail] user \"uid:%d\" email has been verified", user.Uid)
|
||||
return errs.ErrEmailIsVerified
|
||||
}
|
||||
|
||||
token, _, err := l.tokens.CreateEmailVerifyToken(nil, user)
|
||||
token, _, err := l.tokens.CreateEmailVerifyTokenWithoutUserAgent(c, user)
|
||||
|
||||
if err != nil {
|
||||
log.BootErrorf("[user_data.ResendVerifyEmail] failed to create token for user \"uid:%d\", because %s", user.Uid, err.Error())
|
||||
log.BootErrorf(c, "[user_data.ResendVerifyEmail] failed to create token for user \"uid:%d\", because %s", user.Uid, err.Error())
|
||||
return errs.ErrTokenGenerating
|
||||
}
|
||||
|
||||
err = l.users.SendVerifyEmail(user, token, "")
|
||||
|
||||
if err != nil {
|
||||
log.BootErrorf("[user_data.ResendVerifyEmail] cannot send email to \"%s\", because %s", user.Email, err.Error())
|
||||
log.BootErrorf(c, "[user_data.ResendVerifyEmail] cannot send email to \"%s\", because %s", user.Email, err.Error())
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -281,16 +280,16 @@ func (l *UserDataCli) ResendVerifyEmail(c *cli.Context, username string) error {
|
||||
}
|
||||
|
||||
// SetUserEmailVerified sets user email address verified
|
||||
func (l *UserDataCli) SetUserEmailVerified(c *cli.Context, username string) error {
|
||||
func (l *UserDataCli) SetUserEmailVerified(c *core.CliContext, username string) error {
|
||||
if username == "" {
|
||||
log.BootErrorf("[user_data.SetUserEmailVerified] user name is empty")
|
||||
log.BootErrorf(c, "[user_data.SetUserEmailVerified] user name is empty")
|
||||
return errs.ErrUsernameIsEmpty
|
||||
}
|
||||
|
||||
err := l.users.SetUserEmailVerified(nil, username)
|
||||
err := l.users.SetUserEmailVerified(c, username)
|
||||
|
||||
if err != nil {
|
||||
log.BootErrorf("[user_data.SetUserEmailVerified] failed to set user email address verified by user name \"%s\", because %s", username, err.Error())
|
||||
log.BootErrorf(c, "[user_data.SetUserEmailVerified] failed to set user email address verified by user name \"%s\", because %s", username, err.Error())
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -298,16 +297,16 @@ func (l *UserDataCli) SetUserEmailVerified(c *cli.Context, username string) erro
|
||||
}
|
||||
|
||||
// SetUserEmailUnverified sets user email address unverified
|
||||
func (l *UserDataCli) SetUserEmailUnverified(c *cli.Context, username string) error {
|
||||
func (l *UserDataCli) SetUserEmailUnverified(c *core.CliContext, username string) error {
|
||||
if username == "" {
|
||||
log.BootErrorf("[user_data.SetUserEmailUnverified] user name is empty")
|
||||
log.BootErrorf(c, "[user_data.SetUserEmailUnverified] user name is empty")
|
||||
return errs.ErrUsernameIsEmpty
|
||||
}
|
||||
|
||||
err := l.users.SetUserEmailUnverified(nil, username)
|
||||
err := l.users.SetUserEmailUnverified(c, username)
|
||||
|
||||
if err != nil {
|
||||
log.BootErrorf("[user_data.SetUserEmailUnverified] failed to set user email address unverified by user name \"%s\", because %s", username, err.Error())
|
||||
log.BootErrorf(c, "[user_data.SetUserEmailUnverified] failed to set user email address unverified by user name \"%s\", because %s", username, err.Error())
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -315,16 +314,16 @@ func (l *UserDataCli) SetUserEmailUnverified(c *cli.Context, username string) er
|
||||
}
|
||||
|
||||
// DeleteUser deletes user according to the specified user name
|
||||
func (l *UserDataCli) DeleteUser(c *cli.Context, username string) error {
|
||||
func (l *UserDataCli) DeleteUser(c *core.CliContext, username string) error {
|
||||
if username == "" {
|
||||
log.BootErrorf("[user_data.DeleteUser] user name is empty")
|
||||
log.BootErrorf(c, "[user_data.DeleteUser] user name is empty")
|
||||
return errs.ErrUsernameIsEmpty
|
||||
}
|
||||
|
||||
err := l.users.DeleteUser(nil, username)
|
||||
err := l.users.DeleteUser(c, username)
|
||||
|
||||
if err != nil {
|
||||
log.BootErrorf("[user_data.DeleteUser] failed to delete user by user name \"%s\", because %s", username, err.Error())
|
||||
log.BootErrorf(c, "[user_data.DeleteUser] failed to delete user by user name \"%s\", because %s", username, err.Error())
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -332,23 +331,23 @@ func (l *UserDataCli) DeleteUser(c *cli.Context, username string) error {
|
||||
}
|
||||
|
||||
// ListUserTokens returns all tokens of the specified user
|
||||
func (l *UserDataCli) ListUserTokens(c *cli.Context, username string) ([]*models.TokenRecord, error) {
|
||||
func (l *UserDataCli) ListUserTokens(c *core.CliContext, username string) ([]*models.TokenRecord, error) {
|
||||
if username == "" {
|
||||
log.BootErrorf("[user_data.ListUserTokens] user name is empty")
|
||||
log.BootErrorf(c, "[user_data.ListUserTokens] user name is empty")
|
||||
return nil, errs.ErrUsernameIsEmpty
|
||||
}
|
||||
|
||||
uid, err := l.getUserIdByUsername(c, username)
|
||||
|
||||
if err != nil {
|
||||
log.BootErrorf("[user_data.ListUserTokens] error occurs when getting user id by user name")
|
||||
log.BootErrorf(c, "[user_data.ListUserTokens] error occurs when getting user id by user name")
|
||||
return nil, err
|
||||
}
|
||||
|
||||
tokens, err := l.tokens.GetAllUnexpiredNormalTokensByUid(nil, uid)
|
||||
tokens, err := l.tokens.GetAllUnexpiredNormalTokensByUid(c, uid)
|
||||
|
||||
if err != nil {
|
||||
log.BootErrorf("[user_data.ListUserTokens] failed to get tokens of user \"%s\", because %s", username, err.Error())
|
||||
log.BootErrorf(c, "[user_data.ListUserTokens] failed to get tokens of user \"%s\", because %s", username, err.Error())
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -356,24 +355,24 @@ func (l *UserDataCli) ListUserTokens(c *cli.Context, username string) ([]*models
|
||||
}
|
||||
|
||||
// ClearUserTokens clears all tokens of the specified user
|
||||
func (l *UserDataCli) ClearUserTokens(c *cli.Context, username string) error {
|
||||
func (l *UserDataCli) ClearUserTokens(c *core.CliContext, username string) error {
|
||||
if username == "" {
|
||||
log.BootErrorf("[user_data.ClearUserTokens] user name is empty")
|
||||
log.BootErrorf(c, "[user_data.ClearUserTokens] user name is empty")
|
||||
return errs.ErrUsernameIsEmpty
|
||||
}
|
||||
|
||||
uid, err := l.getUserIdByUsername(c, username)
|
||||
|
||||
if err != nil {
|
||||
log.BootErrorf("[user_data.ClearUserTokens] error occurs when getting user id by user name")
|
||||
log.BootErrorf(c, "[user_data.ClearUserTokens] error occurs when getting user id by user name")
|
||||
return err
|
||||
}
|
||||
|
||||
now := time.Now().Unix()
|
||||
err = l.tokens.DeleteTokensBeforeTime(nil, uid, now)
|
||||
err = l.tokens.DeleteTokensBeforeTime(c, uid, now)
|
||||
|
||||
if err != nil {
|
||||
log.BootErrorf("[user_data.ClearUserTokens] failed to delete tokens of user \"%s\", because %s", username, err.Error())
|
||||
log.BootErrorf(c, "[user_data.ClearUserTokens] failed to delete tokens of user \"%s\", because %s", username, err.Error())
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -381,23 +380,23 @@ func (l *UserDataCli) ClearUserTokens(c *cli.Context, username string) error {
|
||||
}
|
||||
|
||||
// DisableUserTwoFactorAuthorization disables 2fa for the specified user
|
||||
func (l *UserDataCli) DisableUserTwoFactorAuthorization(c *cli.Context, username string) error {
|
||||
func (l *UserDataCli) DisableUserTwoFactorAuthorization(c *core.CliContext, username string) error {
|
||||
if username == "" {
|
||||
log.BootErrorf("[user_data.DisableUserTwoFactorAuthorization] user name is empty")
|
||||
log.BootErrorf(c, "[user_data.DisableUserTwoFactorAuthorization] user name is empty")
|
||||
return errs.ErrUsernameIsEmpty
|
||||
}
|
||||
|
||||
uid, err := l.getUserIdByUsername(c, username)
|
||||
|
||||
if err != nil {
|
||||
log.BootErrorf("[user_data.DisableUserTwoFactorAuthorization] error occurs when getting user id by user name")
|
||||
log.BootErrorf(c, "[user_data.DisableUserTwoFactorAuthorization] error occurs when getting user id by user name")
|
||||
return err
|
||||
}
|
||||
|
||||
enableTwoFactor, err := l.twoFactorAuthorizations.ExistsTwoFactorSetting(nil, uid)
|
||||
enableTwoFactor, err := l.twoFactorAuthorizations.ExistsTwoFactorSetting(c, uid)
|
||||
|
||||
if err != nil {
|
||||
log.BootErrorf("[user_data.DisableUserTwoFactorAuthorization] failed to check two-factor setting, because %s", err.Error())
|
||||
log.BootErrorf(c, "[user_data.DisableUserTwoFactorAuthorization] failed to check two-factor setting, because %s", err.Error())
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -405,17 +404,17 @@ func (l *UserDataCli) DisableUserTwoFactorAuthorization(c *cli.Context, username
|
||||
return errs.ErrTwoFactorIsNotEnabled
|
||||
}
|
||||
|
||||
err = l.twoFactorAuthorizations.DeleteTwoFactorRecoveryCodes(nil, uid)
|
||||
err = l.twoFactorAuthorizations.DeleteTwoFactorRecoveryCodes(c, uid)
|
||||
|
||||
if err != nil {
|
||||
log.BootErrorf("[user_data.DisableUserTwoFactorAuthorization] failed to delete two-factor recovery codes for user \"%s\"", username)
|
||||
log.BootErrorf(c, "[user_data.DisableUserTwoFactorAuthorization] failed to delete two-factor recovery codes for user \"%s\"", username)
|
||||
return err
|
||||
}
|
||||
|
||||
err = l.twoFactorAuthorizations.DeleteTwoFactorSetting(nil, uid)
|
||||
err = l.twoFactorAuthorizations.DeleteTwoFactorSetting(c, uid)
|
||||
|
||||
if err != nil {
|
||||
log.BootErrorf("[user_data.DisableUserTwoFactorAuthorization] failed to delete two-factor setting for user \"%s\"", username)
|
||||
log.BootErrorf(c, "[user_data.DisableUserTwoFactorAuthorization] failed to delete two-factor setting for user \"%s\"", username)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -423,23 +422,23 @@ func (l *UserDataCli) DisableUserTwoFactorAuthorization(c *cli.Context, username
|
||||
}
|
||||
|
||||
// CheckTransactionAndAccount checks whether all user transactions and all user accounts are correct
|
||||
func (l *UserDataCli) CheckTransactionAndAccount(c *cli.Context, username string) (bool, error) {
|
||||
func (l *UserDataCli) CheckTransactionAndAccount(c *core.CliContext, username string) (bool, error) {
|
||||
if username == "" {
|
||||
log.BootErrorf("[user_data.CheckTransactionAndAccount] user name is empty")
|
||||
log.BootErrorf(c, "[user_data.CheckTransactionAndAccount] user name is empty")
|
||||
return false, errs.ErrUsernameIsEmpty
|
||||
}
|
||||
|
||||
uid, err := l.getUserIdByUsername(c, username)
|
||||
|
||||
if err != nil {
|
||||
log.BootErrorf("[user_data.CheckTransactionAndAccount] error occurs when getting user id by user name")
|
||||
log.BootErrorf(c, "[user_data.CheckTransactionAndAccount] error occurs when getting user id by user name")
|
||||
return false, err
|
||||
}
|
||||
|
||||
accountMap, categoryMap, tagMap, tagIndexes, tagIndexesMap, err := l.getUserEssentialData(uid, username)
|
||||
accountMap, categoryMap, tagMap, tagIndexes, tagIndexesMap, err := l.getUserEssentialData(c, uid, username)
|
||||
|
||||
if err != nil {
|
||||
log.BootErrorf("[user_data.CheckTransactionAndAccount] failed to get essential data for user \"%s\", because %s", username, err.Error())
|
||||
log.BootErrorf(c, "[user_data.CheckTransactionAndAccount] failed to get essential data for user \"%s\", because %s", username, err.Error())
|
||||
return false, err
|
||||
}
|
||||
|
||||
@@ -451,10 +450,10 @@ func (l *UserDataCli) CheckTransactionAndAccount(c *cli.Context, username string
|
||||
}
|
||||
}
|
||||
|
||||
allTransactions, err := l.transactions.GetAllTransactions(nil, uid, pageCountForGettingTransactions, false)
|
||||
allTransactions, err := l.transactions.GetAllTransactions(c, uid, pageCountForGettingTransactions, false)
|
||||
|
||||
if err != nil {
|
||||
log.BootErrorf("[user_data.CheckTransactionAndAccount] failed to all transactions for user \"%s\", because %s", username, err.Error())
|
||||
log.BootErrorf(c, "[user_data.CheckTransactionAndAccount] failed to all transactions for user \"%s\", because %s", username, err.Error())
|
||||
return false, err
|
||||
}
|
||||
|
||||
@@ -505,7 +504,7 @@ func (l *UserDataCli) CheckTransactionAndAccount(c *cli.Context, username string
|
||||
} else if transaction.Type == models.TRANSACTION_DB_TYPE_TRANSFER_IN {
|
||||
balance = balance + transaction.Amount
|
||||
} else {
|
||||
log.BootErrorf("[user_data.CheckTransactionAndAccount] transaction type of transaction \"id:%d\" is invalid", transaction.TransactionId)
|
||||
log.BootErrorf(c, "[user_data.CheckTransactionAndAccount] transaction type of transaction \"id:%d\" is invalid", transaction.TransactionId)
|
||||
return false, errs.ErrOperationFailed
|
||||
}
|
||||
|
||||
@@ -520,12 +519,12 @@ func (l *UserDataCli) CheckTransactionAndAccount(c *cli.Context, username string
|
||||
}
|
||||
|
||||
if !exists && account.Balance != 0 {
|
||||
log.BootErrorf("[user_data.CheckTransactionAndAccount] account \"id:%d\" balance is not correct, expected balance is %d, but there is no transaction actually", account.AccountId, account.Balance)
|
||||
log.BootErrorf(c, "[user_data.CheckTransactionAndAccount] account \"id:%d\" balance is not correct, expected balance is %d, but there is no transaction actually", account.AccountId, account.Balance)
|
||||
return false, errs.ErrOperationFailed
|
||||
}
|
||||
|
||||
if account.Balance != actualBalance {
|
||||
log.BootErrorf("[user_data.CheckTransactionAndAccount] account \"id:%d\" balance is not correct, expected balance is %d, but actual balance is %d", account.AccountId, account.Balance, actualBalance)
|
||||
log.BootErrorf(c, "[user_data.CheckTransactionAndAccount] account \"id:%d\" balance is not correct, expected balance is %d, but actual balance is %d", account.AccountId, account.Balance, actualBalance)
|
||||
return false, errs.ErrOperationFailed
|
||||
}
|
||||
}
|
||||
@@ -534,7 +533,7 @@ func (l *UserDataCli) CheckTransactionAndAccount(c *cli.Context, username string
|
||||
_, exists := accountMap[accountId]
|
||||
|
||||
if !exists {
|
||||
log.BootErrorf("[user_data.CheckTransactionAndAccount] account \"id:%d\" does not exist, but there are some transactions of this account actually, and actual balance is %d", accountId, actualBalance)
|
||||
log.BootErrorf(c, "[user_data.CheckTransactionAndAccount] account \"id:%d\" does not exist, but there are some transactions of this account actually, and actual balance is %d", accountId, actualBalance)
|
||||
return false, errs.ErrOperationFailed
|
||||
}
|
||||
}
|
||||
@@ -543,7 +542,7 @@ func (l *UserDataCli) CheckTransactionAndAccount(c *cli.Context, username string
|
||||
tagIndex := tagIndexes[i]
|
||||
|
||||
if tagIndex.TransactionTime < 1 {
|
||||
log.BootErrorf("[user_data.CheckTransactionAndAccount] transaction tag index \"id:%d\" does not have transaction time", tagIndex.TagIndexId)
|
||||
log.BootErrorf(c, "[user_data.CheckTransactionAndAccount] transaction tag index \"id:%d\" does not have transaction time", tagIndex.TagIndexId)
|
||||
return false, errs.ErrOperationFailed
|
||||
}
|
||||
}
|
||||
@@ -552,23 +551,23 @@ func (l *UserDataCli) CheckTransactionAndAccount(c *cli.Context, username string
|
||||
}
|
||||
|
||||
// FixTransactionTagIndexWithTransactionTime fixes user transaction tag index data with transaction time
|
||||
func (l *UserDataCli) FixTransactionTagIndexWithTransactionTime(c *cli.Context, username string) (bool, error) {
|
||||
func (l *UserDataCli) FixTransactionTagIndexWithTransactionTime(c *core.CliContext, username string) (bool, error) {
|
||||
if username == "" {
|
||||
log.BootErrorf("[user_data.FixTransactionTagIndexWithTransactionTime] user name is empty")
|
||||
log.BootErrorf(c, "[user_data.FixTransactionTagIndexWithTransactionTime] user name is empty")
|
||||
return false, errs.ErrUsernameIsEmpty
|
||||
}
|
||||
|
||||
uid, err := l.getUserIdByUsername(c, username)
|
||||
|
||||
if err != nil {
|
||||
log.BootErrorf("[user_data.FixTransactionTagIndexWithTransactionTime] error occurs when getting user id by user name")
|
||||
log.BootErrorf(c, "[user_data.FixTransactionTagIndexWithTransactionTime] error occurs when getting user id by user name")
|
||||
return false, err
|
||||
}
|
||||
|
||||
tagIndexes, err := l.tags.GetAllTagIdsOfAllTransactions(nil, uid)
|
||||
tagIndexes, err := l.tags.GetAllTagIdsOfAllTransactions(c, uid)
|
||||
|
||||
if err != nil {
|
||||
log.BootErrorf("[user_data.FixTransactionTagIndexWithTransactionTime] failed to get tag index for user \"%s\", because %s", username, err.Error())
|
||||
log.BootErrorf(c, "[user_data.FixTransactionTagIndexWithTransactionTime] failed to get tag index for user \"%s\", because %s", username, err.Error())
|
||||
return false, err
|
||||
}
|
||||
|
||||
@@ -583,14 +582,14 @@ func (l *UserDataCli) FixTransactionTagIndexWithTransactionTime(c *cli.Context,
|
||||
}
|
||||
|
||||
if len(invalidTagIndexes) < 1 {
|
||||
log.BootErrorf("[user_data.FixTransactionTagIndexWithTransactionTime] all user transaction tag index data has been checked, there is no problem with user data")
|
||||
log.BootErrorf(c, "[user_data.FixTransactionTagIndexWithTransactionTime] all user transaction tag index data has been checked, there is no problem with user data")
|
||||
return false, errs.ErrOperationFailed
|
||||
}
|
||||
|
||||
allTransactions, err := l.transactions.GetAllTransactions(nil, uid, pageCountForGettingTransactions, false)
|
||||
allTransactions, err := l.transactions.GetAllTransactions(c, uid, pageCountForGettingTransactions, false)
|
||||
|
||||
if err != nil {
|
||||
log.BootErrorf("[user_data.FixTransactionTagIndexWithTransactionTime] failed to all transactions for user \"%s\", because %s", username, err.Error())
|
||||
log.BootErrorf(c, "[user_data.FixTransactionTagIndexWithTransactionTime] failed to all transactions for user \"%s\", because %s", username, err.Error())
|
||||
return false, err
|
||||
}
|
||||
|
||||
@@ -607,10 +606,10 @@ func (l *UserDataCli) FixTransactionTagIndexWithTransactionTime(c *cli.Context,
|
||||
tagIndex.TransactionTime = transaction.TransactionTime
|
||||
}
|
||||
|
||||
err = l.tags.ModifyTagIndexTransactionTime(nil, uid, invalidTagIndexes)
|
||||
err = l.tags.ModifyTagIndexTransactionTime(c, uid, invalidTagIndexes)
|
||||
|
||||
if err != nil {
|
||||
log.BootErrorf("[user_data.FixTransactionTagIndexWithTransactionTime] failed to update transaction tag index for user \"%s\", because %s", username, err.Error())
|
||||
log.BootErrorf(c, "[user_data.FixTransactionTagIndexWithTransactionTime] failed to update transaction tag index for user \"%s\", because %s", username, err.Error())
|
||||
return false, err
|
||||
}
|
||||
|
||||
@@ -618,30 +617,30 @@ func (l *UserDataCli) FixTransactionTagIndexWithTransactionTime(c *cli.Context,
|
||||
}
|
||||
|
||||
// ExportTransaction returns csv file content according user all transactions
|
||||
func (l *UserDataCli) ExportTransaction(c *cli.Context, username string, fileType string) ([]byte, error) {
|
||||
func (l *UserDataCli) ExportTransaction(c *core.CliContext, username string, fileType string) ([]byte, error) {
|
||||
if username == "" {
|
||||
log.BootErrorf("[user_data.ExportTransaction] user name is empty")
|
||||
log.BootErrorf(c, "[user_data.ExportTransaction] user name is empty")
|
||||
return nil, errs.ErrUsernameIsEmpty
|
||||
}
|
||||
|
||||
uid, err := l.getUserIdByUsername(c, username)
|
||||
|
||||
if err != nil {
|
||||
log.BootErrorf("[user_data.ExportTransaction] error occurs when getting user id by user name")
|
||||
log.BootErrorf(c, "[user_data.ExportTransaction] error occurs when getting user id by user name")
|
||||
return nil, err
|
||||
}
|
||||
|
||||
accountMap, categoryMap, tagMap, _, tagIndexesMap, err := l.getUserEssentialData(uid, username)
|
||||
accountMap, categoryMap, tagMap, _, tagIndexesMap, err := l.getUserEssentialData(c, uid, username)
|
||||
|
||||
if err != nil {
|
||||
log.BootErrorf("[user_data.ExportTransaction] failed to get essential data for user \"%s\", because %s", username, err.Error())
|
||||
log.BootErrorf(c, "[user_data.ExportTransaction] failed to get essential data for user \"%s\", because %s", username, err.Error())
|
||||
return nil, err
|
||||
}
|
||||
|
||||
allTransactions, err := l.transactions.GetAllTransactions(nil, uid, pageCountForDataExport, true)
|
||||
allTransactions, err := l.transactions.GetAllTransactions(c, uid, pageCountForDataExport, true)
|
||||
|
||||
if err != nil {
|
||||
log.BootErrorf("[user_data.ExportTransaction] failed to all transactions for user \"%s\", because %s", username, err.Error())
|
||||
log.BootErrorf(c, "[user_data.ExportTransaction] failed to all transactions for user \"%s\", because %s", username, err.Error())
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -656,61 +655,61 @@ func (l *UserDataCli) ExportTransaction(c *cli.Context, username string, fileTyp
|
||||
result, err := dataExporter.ToExportedContent(uid, allTransactions, accountMap, categoryMap, tagMap, tagIndexesMap)
|
||||
|
||||
if err != nil {
|
||||
log.BootErrorf("[user_data.ExportTransaction] failed to get csv format exported data for \"%s\", because %s", username, err.Error())
|
||||
log.BootErrorf(c, "[user_data.ExportTransaction] failed to get csv format exported data for \"%s\", because %s", username, err.Error())
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (l *UserDataCli) getUserIdByUsername(c *cli.Context, username string) (int64, error) {
|
||||
func (l *UserDataCli) getUserIdByUsername(c *core.CliContext, username string) (int64, error) {
|
||||
user, err := l.GetUserByUsername(c, username)
|
||||
|
||||
if err != nil {
|
||||
log.BootErrorf("[user_data.getUserIdByUsername] failed to get user by user name \"%s\", because %s", username, err.Error())
|
||||
log.BootErrorf(c, "[user_data.getUserIdByUsername] failed to get user by user name \"%s\", because %s", username, err.Error())
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return user.Uid, nil
|
||||
}
|
||||
|
||||
func (l *UserDataCli) getUserEssentialData(uid int64, username string) (accountMap map[int64]*models.Account, categoryMap map[int64]*models.TransactionCategory, tagMap map[int64]*models.TransactionTag, tagIndexes []*models.TransactionTagIndex, tagIndexesMap map[int64][]int64, err error) {
|
||||
func (l *UserDataCli) getUserEssentialData(c *core.CliContext, uid int64, username string) (accountMap map[int64]*models.Account, categoryMap map[int64]*models.TransactionCategory, tagMap map[int64]*models.TransactionTag, tagIndexes []*models.TransactionTagIndex, tagIndexesMap map[int64][]int64, err error) {
|
||||
if uid <= 0 {
|
||||
log.BootErrorf("[user_data.getUserEssentialData] user uid \"%d\" is invalid", uid)
|
||||
log.BootErrorf(c, "[user_data.getUserEssentialData] user uid \"%d\" is invalid", uid)
|
||||
return nil, nil, nil, nil, nil, errs.ErrUserIdInvalid
|
||||
}
|
||||
|
||||
accounts, err := l.accounts.GetAllAccountsByUid(nil, uid)
|
||||
accounts, err := l.accounts.GetAllAccountsByUid(c, uid)
|
||||
|
||||
if err != nil {
|
||||
log.BootErrorf("[user_data.getUserEssentialData] failed to get accounts for user \"%s\", because %s", username, err.Error())
|
||||
log.BootErrorf(c, "[user_data.getUserEssentialData] failed to get accounts for user \"%s\", because %s", username, err.Error())
|
||||
return nil, nil, nil, nil, nil, err
|
||||
}
|
||||
|
||||
accountMap = l.accounts.GetAccountMapByList(accounts)
|
||||
|
||||
categories, err := l.categories.GetAllCategoriesByUid(nil, uid, 0, -1)
|
||||
categories, err := l.categories.GetAllCategoriesByUid(c, uid, 0, -1)
|
||||
|
||||
if err != nil {
|
||||
log.BootErrorf("[user_data.getUserEssentialData] failed to get categories for user \"%s\", because %s", username, err.Error())
|
||||
log.BootErrorf(c, "[user_data.getUserEssentialData] failed to get categories for user \"%s\", because %s", username, err.Error())
|
||||
return nil, nil, nil, nil, nil, err
|
||||
}
|
||||
|
||||
categoryMap = l.categories.GetCategoryMapByList(categories)
|
||||
|
||||
tags, err := l.tags.GetAllTagsByUid(nil, uid)
|
||||
tags, err := l.tags.GetAllTagsByUid(c, uid)
|
||||
|
||||
if err != nil {
|
||||
log.BootErrorf("[user_data.getUserEssentialData] failed to get tags for user \"%s\", because %s", username, err.Error())
|
||||
log.BootErrorf(c, "[user_data.getUserEssentialData] failed to get tags for user \"%s\", because %s", username, err.Error())
|
||||
return nil, nil, nil, nil, nil, err
|
||||
}
|
||||
|
||||
tagMap = l.tags.GetTagMapByList(tags)
|
||||
|
||||
tagIndexes, err = l.tags.GetAllTagIdsOfAllTransactions(nil, uid)
|
||||
tagIndexes, err = l.tags.GetAllTagIdsOfAllTransactions(c, uid)
|
||||
|
||||
if err != nil {
|
||||
log.BootErrorf("[user_data.getUserEssentialData] failed to get tag index for user \"%s\", because %s", username, err.Error())
|
||||
log.BootErrorf(c, "[user_data.getUserEssentialData] failed to get tag index for user \"%s\", because %s", username, err.Error())
|
||||
return nil, nil, nil, nil, nil, err
|
||||
}
|
||||
|
||||
@@ -719,16 +718,16 @@ func (l *UserDataCli) getUserEssentialData(uid int64, username string) (accountM
|
||||
return accountMap, categoryMap, tagMap, tagIndexes, tagIndexesMap, nil
|
||||
}
|
||||
|
||||
func (l *UserDataCli) checkTransactionAccount(c *cli.Context, transaction *models.Transaction, accountMap map[int64]*models.Account, accountHasChild map[int64]bool) error {
|
||||
func (l *UserDataCli) checkTransactionAccount(c *core.CliContext, transaction *models.Transaction, accountMap map[int64]*models.Account, accountHasChild map[int64]bool) error {
|
||||
account, exists := accountMap[transaction.AccountId]
|
||||
|
||||
if !exists {
|
||||
log.BootErrorf("[user_data.checkTransactionAccount] the account \"id:%d\" of transaction \"id:%d\" does not exist", transaction.AccountId, transaction.TransactionId)
|
||||
log.BootErrorf(c, "[user_data.checkTransactionAccount] the account \"id:%d\" of transaction \"id:%d\" does not exist", transaction.AccountId, transaction.TransactionId)
|
||||
return errs.ErrAccountNotFound
|
||||
}
|
||||
|
||||
if account.ParentAccountId == models.LevelOneAccountParentId && accountHasChild[account.AccountId] {
|
||||
log.BootErrorf("[user_data.checkTransactionAccount] the account \"id:%d\" of transaction \"id:%d\" is not a sub-account", transaction.AccountId, transaction.TransactionId)
|
||||
log.BootErrorf(c, "[user_data.checkTransactionAccount] the account \"id:%d\" of transaction \"id:%d\" is not a sub-account", transaction.AccountId, transaction.TransactionId)
|
||||
return errs.ErrOperationFailed
|
||||
}
|
||||
|
||||
@@ -736,12 +735,12 @@ func (l *UserDataCli) checkTransactionAccount(c *cli.Context, transaction *model
|
||||
relatedAccount, exists := accountMap[transaction.RelatedAccountId]
|
||||
|
||||
if !exists {
|
||||
log.BootErrorf("[user_data.checkTransactionAccount] the related account \"id:%d\" of transaction \"id:%d\" does not exist", transaction.RelatedAccountId, transaction.TransactionId)
|
||||
log.BootErrorf(c, "[user_data.checkTransactionAccount] the related account \"id:%d\" of transaction \"id:%d\" does not exist", transaction.RelatedAccountId, transaction.TransactionId)
|
||||
return errs.ErrAccountNotFound
|
||||
}
|
||||
|
||||
if relatedAccount.ParentAccountId == models.LevelOneAccountParentId && accountHasChild[relatedAccount.AccountId] {
|
||||
log.BootErrorf("[user_data.checkTransactionAccount] the related account \"id:%d\" of transaction \"id:%d\" is not a sub-account", transaction.RelatedAccountId, transaction.TransactionId)
|
||||
log.BootErrorf(c, "[user_data.checkTransactionAccount] the related account \"id:%d\" of transaction \"id:%d\" is not a sub-account", transaction.RelatedAccountId, transaction.TransactionId)
|
||||
return errs.ErrOperationFailed
|
||||
}
|
||||
}
|
||||
@@ -749,10 +748,10 @@ func (l *UserDataCli) checkTransactionAccount(c *cli.Context, transaction *model
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l *UserDataCli) checkTransactionCategory(c *cli.Context, transaction *models.Transaction, categoryMap map[int64]*models.TransactionCategory) error {
|
||||
func (l *UserDataCli) checkTransactionCategory(c *core.CliContext, transaction *models.Transaction, categoryMap map[int64]*models.TransactionCategory) error {
|
||||
if transaction.Type == models.TRANSACTION_DB_TYPE_MODIFY_BALANCE {
|
||||
if transaction.CategoryId > 0 {
|
||||
log.BootErrorf("[user_data.checkTransactionCategory] transaction \"id:%d\" is balance modification transaction, but has category \"id:%d\"", transaction.TransactionId, transaction.CategoryId)
|
||||
log.BootErrorf(c, "[user_data.checkTransactionCategory] transaction \"id:%d\" is balance modification transaction, but has category \"id:%d\"", transaction.TransactionId, transaction.CategoryId)
|
||||
return errs.ErrBalanceModificationTransactionCannotSetCategory
|
||||
} else {
|
||||
return nil
|
||||
@@ -762,19 +761,19 @@ func (l *UserDataCli) checkTransactionCategory(c *cli.Context, transaction *mode
|
||||
category, exists := categoryMap[transaction.CategoryId]
|
||||
|
||||
if !exists {
|
||||
log.BootErrorf("[user_data.checkTransactionCategory] the transaction category \"id:%d\" of transaction \"id:%d\" does not exist", transaction.CategoryId, transaction.TransactionId)
|
||||
log.BootErrorf(c, "[user_data.checkTransactionCategory] the transaction category \"id:%d\" of transaction \"id:%d\" does not exist", transaction.CategoryId, transaction.TransactionId)
|
||||
return errs.ErrTransactionCategoryNotFound
|
||||
}
|
||||
|
||||
if category.ParentCategoryId == models.LevelOneTransactionParentId {
|
||||
log.BootErrorf("[user_data.checkTransactionCategory] the transaction category \"id:%d\" of transaction \"id:%d\" is not a sub category", transaction.CategoryId, transaction.TransactionId)
|
||||
log.BootErrorf(c, "[user_data.checkTransactionCategory] the transaction category \"id:%d\" of transaction \"id:%d\" is not a sub category", transaction.CategoryId, transaction.TransactionId)
|
||||
return errs.ErrOperationFailed
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l *UserDataCli) checkTransactionTag(c *cli.Context, transactionId int64, allTagIndexesMap map[int64][]int64, tagMap map[int64]*models.TransactionTag) error {
|
||||
func (l *UserDataCli) checkTransactionTag(c *core.CliContext, transactionId int64, allTagIndexesMap map[int64][]int64, tagMap map[int64]*models.TransactionTag) error {
|
||||
tagIndexes, exists := allTagIndexesMap[transactionId]
|
||||
|
||||
if !exists {
|
||||
@@ -786,7 +785,7 @@ func (l *UserDataCli) checkTransactionTag(c *cli.Context, transactionId int64, a
|
||||
tag, exists := tagMap[tagIndex]
|
||||
|
||||
if !exists {
|
||||
log.BootErrorf("[user_data.checkTransactionTag] the transaction tag \"id:%d\" of transaction \"id:%d\" does not exist", tag.TagId, transactionId)
|
||||
log.BootErrorf(c, "[user_data.checkTransactionTag] the transaction tag \"id:%d\" of transaction \"id:%d\" does not exist", tag.TagId, transactionId)
|
||||
return errs.ErrTransactionTagNotFound
|
||||
}
|
||||
}
|
||||
@@ -794,7 +793,7 @@ func (l *UserDataCli) checkTransactionTag(c *cli.Context, transactionId int64, a
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l *UserDataCli) checkTransactionRelatedTransaction(c *cli.Context, transaction *models.Transaction, transactionMap map[int64]*models.Transaction, accountMap map[int64]*models.Account) error {
|
||||
func (l *UserDataCli) checkTransactionRelatedTransaction(c *core.CliContext, transaction *models.Transaction, transactionMap map[int64]*models.Transaction, accountMap map[int64]*models.Account) error {
|
||||
if transaction.Type != models.TRANSACTION_DB_TYPE_TRANSFER_OUT && transaction.Type != models.TRANSACTION_DB_TYPE_TRANSFER_IN {
|
||||
return nil
|
||||
}
|
||||
@@ -802,22 +801,22 @@ func (l *UserDataCli) checkTransactionRelatedTransaction(c *cli.Context, transac
|
||||
relatedTransaction, exists := transactionMap[transaction.RelatedId]
|
||||
|
||||
if !exists {
|
||||
log.BootErrorf("[user_data.checkTransactionRelatedTransaction] the related transaction \"id:%d\" of transaction \"id:%d\" does not exist", transaction.RelatedId, transaction.TransactionId)
|
||||
log.BootErrorf(c, "[user_data.checkTransactionRelatedTransaction] the related transaction \"id:%d\" of transaction \"id:%d\" does not exist", transaction.RelatedId, transaction.TransactionId)
|
||||
return errs.ErrTransactionNotFound
|
||||
}
|
||||
|
||||
if transaction.RelatedId != relatedTransaction.TransactionId || transaction.TransactionId != relatedTransaction.RelatedId {
|
||||
log.BootErrorf("[user_data.checkTransactionRelatedTransaction] related ids of transaction \"id:%d\" and transaction \"id:%d\" are not equal", transaction.RelatedId, transaction.TransactionId)
|
||||
log.BootErrorf(c, "[user_data.checkTransactionRelatedTransaction] related ids of transaction \"id:%d\" and transaction \"id:%d\" are not equal", transaction.RelatedId, transaction.TransactionId)
|
||||
return errs.ErrOperationFailed
|
||||
}
|
||||
|
||||
if transaction.RelatedAccountId != relatedTransaction.AccountId || transaction.AccountId != relatedTransaction.RelatedAccountId {
|
||||
log.BootErrorf("[user_data.checkTransactionRelatedTransaction] related account ids of transaction \"id:%d\" and transaction \"id:%d\" are not equal", transaction.RelatedId, transaction.TransactionId)
|
||||
log.BootErrorf(c, "[user_data.checkTransactionRelatedTransaction] related account ids of transaction \"id:%d\" and transaction \"id:%d\" are not equal", transaction.RelatedId, transaction.TransactionId)
|
||||
return errs.ErrOperationFailed
|
||||
}
|
||||
|
||||
if transaction.RelatedAccountAmount != relatedTransaction.Amount || transaction.Amount != relatedTransaction.RelatedAccountAmount {
|
||||
log.BootErrorf("[user_data.checkTransactionRelatedTransaction] related amounts of transaction \"id:%d\" and transaction \"id:%d\" are not equal", transaction.RelatedId, transaction.TransactionId)
|
||||
log.BootErrorf(c, "[user_data.checkTransactionRelatedTransaction] related amounts of transaction \"id:%d\" and transaction \"id:%d\" are not equal", transaction.RelatedId, transaction.TransactionId)
|
||||
return errs.ErrOperationFailed
|
||||
}
|
||||
|
||||
@@ -825,7 +824,7 @@ func (l *UserDataCli) checkTransactionRelatedTransaction(c *cli.Context, transac
|
||||
relatedAccount := accountMap[transaction.RelatedAccountId]
|
||||
|
||||
if account.Currency == relatedAccount.Currency && transaction.Amount != transaction.RelatedAccountAmount {
|
||||
log.BootWarnf("[user_data.checkTransactionRelatedTransaction] transfer-in amount and transfer-out amount of transaction \"id:%d\" are not equal", transaction.TransactionId)
|
||||
log.BootWarnf(c, "[user_data.checkTransactionRelatedTransaction] transfer-in amount and transfer-out amount of transaction \"id:%d\" are not equal", transaction.TransactionId)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user