code refactor

This commit is contained in:
MaysWind
2024-08-19 00:31:32 +08:00
parent 6fcb0a2b3c
commit e86d4e05ce
73 changed files with 1404 additions and 1344 deletions
+13 -13
View File
@@ -33,7 +33,7 @@ var (
)
// GetTotalAccountCountByUid returns total account count of user
func (s *AccountService) GetTotalAccountCountByUid(c *core.Context, uid int64) (int64, error) {
func (s *AccountService) GetTotalAccountCountByUid(c core.Context, uid int64) (int64, error) {
if uid <= 0 {
return 0, errs.ErrUserIdInvalid
}
@@ -44,7 +44,7 @@ func (s *AccountService) GetTotalAccountCountByUid(c *core.Context, uid int64) (
}
// GetAllAccountsByUid returns all account models of user
func (s *AccountService) GetAllAccountsByUid(c *core.Context, uid int64) ([]*models.Account, error) {
func (s *AccountService) GetAllAccountsByUid(c core.Context, uid int64) ([]*models.Account, error) {
if uid <= 0 {
return nil, errs.ErrUserIdInvalid
}
@@ -56,7 +56,7 @@ func (s *AccountService) GetAllAccountsByUid(c *core.Context, uid int64) ([]*mod
}
// GetAccountAndSubAccountsByAccountId returns account model and sub-account models according to account id
func (s *AccountService) GetAccountAndSubAccountsByAccountId(c *core.Context, uid int64, accountId int64) ([]*models.Account, error) {
func (s *AccountService) GetAccountAndSubAccountsByAccountId(c core.Context, uid int64, accountId int64) ([]*models.Account, error) {
if uid <= 0 {
return nil, errs.ErrUserIdInvalid
}
@@ -72,7 +72,7 @@ func (s *AccountService) GetAccountAndSubAccountsByAccountId(c *core.Context, ui
}
// GetSubAccountsByAccountId returns sub-account models according to account id
func (s *AccountService) GetSubAccountsByAccountId(c *core.Context, uid int64, accountId int64) ([]*models.Account, error) {
func (s *AccountService) GetSubAccountsByAccountId(c core.Context, uid int64, accountId int64) ([]*models.Account, error) {
if uid <= 0 {
return nil, errs.ErrUserIdInvalid
}
@@ -88,7 +88,7 @@ func (s *AccountService) GetSubAccountsByAccountId(c *core.Context, uid int64, a
}
// GetSubAccountsByAccountIds returns sub-account models according to account ids
func (s *AccountService) GetSubAccountsByAccountIds(c *core.Context, uid int64, accountIds []int64) ([]*models.Account, error) {
func (s *AccountService) GetSubAccountsByAccountIds(c core.Context, uid int64, accountIds []int64) ([]*models.Account, error) {
if uid <= 0 {
return nil, errs.ErrUserIdInvalid
}
@@ -130,7 +130,7 @@ func (s *AccountService) GetSubAccountsByAccountIds(c *core.Context, uid int64,
}
// GetAccountsByAccountIds returns account models according to account ids
func (s *AccountService) GetAccountsByAccountIds(c *core.Context, uid int64, accountIds []int64) (map[int64]*models.Account, error) {
func (s *AccountService) GetAccountsByAccountIds(c core.Context, uid int64, accountIds []int64) (map[int64]*models.Account, error) {
if uid <= 0 {
return nil, errs.ErrUserIdInvalid
}
@@ -151,7 +151,7 @@ func (s *AccountService) GetAccountsByAccountIds(c *core.Context, uid int64, acc
}
// GetMaxDisplayOrder returns the max display order according to account category
func (s *AccountService) GetMaxDisplayOrder(c *core.Context, uid int64, category models.AccountCategory) (int32, error) {
func (s *AccountService) GetMaxDisplayOrder(c core.Context, uid int64, category models.AccountCategory) (int32, error) {
if uid <= 0 {
return 0, errs.ErrUserIdInvalid
}
@@ -171,7 +171,7 @@ func (s *AccountService) GetMaxDisplayOrder(c *core.Context, uid int64, category
}
// GetMaxSubAccountDisplayOrder returns the max display order of sub-account according to account category and parent account id
func (s *AccountService) GetMaxSubAccountDisplayOrder(c *core.Context, uid int64, category models.AccountCategory, parentAccountId int64) (int32, error) {
func (s *AccountService) GetMaxSubAccountDisplayOrder(c core.Context, uid int64, category models.AccountCategory, parentAccountId int64) (int32, error) {
if uid <= 0 {
return 0, errs.ErrUserIdInvalid
}
@@ -195,7 +195,7 @@ func (s *AccountService) GetMaxSubAccountDisplayOrder(c *core.Context, uid int64
}
// CreateAccounts saves a new account model to database
func (s *AccountService) CreateAccounts(c *core.Context, mainAccount *models.Account, childrenAccounts []*models.Account, utcOffset int16) error {
func (s *AccountService) CreateAccounts(c core.Context, mainAccount *models.Account, childrenAccounts []*models.Account, utcOffset int16) error {
if mainAccount.Uid <= 0 {
return errs.ErrUserIdInvalid
}
@@ -288,7 +288,7 @@ func (s *AccountService) CreateAccounts(c *core.Context, mainAccount *models.Acc
}
// ModifyAccounts saves an existed account model to database
func (s *AccountService) ModifyAccounts(c *core.Context, uid int64, accounts []*models.Account) error {
func (s *AccountService) ModifyAccounts(c core.Context, uid int64, accounts []*models.Account) error {
if uid <= 0 {
return errs.ErrUserIdInvalid
}
@@ -316,7 +316,7 @@ func (s *AccountService) ModifyAccounts(c *core.Context, uid int64, accounts []*
}
// HideAccount updates hidden field of given accounts
func (s *AccountService) HideAccount(c *core.Context, uid int64, ids []int64, hidden bool) error {
func (s *AccountService) HideAccount(c core.Context, uid int64, ids []int64, hidden bool) error {
if uid <= 0 {
return errs.ErrUserIdInvalid
}
@@ -342,7 +342,7 @@ func (s *AccountService) HideAccount(c *core.Context, uid int64, ids []int64, hi
}
// ModifyAccountDisplayOrders updates display order of given accounts
func (s *AccountService) ModifyAccountDisplayOrders(c *core.Context, uid int64, accounts []*models.Account) error {
func (s *AccountService) ModifyAccountDisplayOrders(c core.Context, uid int64, accounts []*models.Account) error {
if uid <= 0 {
return errs.ErrUserIdInvalid
}
@@ -368,7 +368,7 @@ func (s *AccountService) ModifyAccountDisplayOrders(c *core.Context, uid int64,
}
// DeleteAccount deletes an existed account from database
func (s *AccountService) DeleteAccount(c *core.Context, uid int64, accountId int64) error {
func (s *AccountService) DeleteAccount(c core.Context, uid int64, accountId int64) error {
if uid <= 0 {
return errs.ErrUserIdInvalid
}
+1 -1
View File
@@ -35,7 +35,7 @@ var (
)
// SendPasswordResetEmail sends password reset email according to specified parameters
func (s *ForgetPasswordService) SendPasswordResetEmail(c *core.Context, user *models.User, passwordResetToken string, backupLocale string) error {
func (s *ForgetPasswordService) SendPasswordResetEmail(c core.Context, user *models.User, passwordResetToken string, backupLocale string) error {
if !s.CurrentConfig().EnableSMTP {
return errs.ErrSMTPServerNotEnabled
}
+39 -29
View File
@@ -38,7 +38,7 @@ var (
)
// GetAllTokensByUid returns all token models of given user
func (s *TokenService) GetAllTokensByUid(c *core.Context, uid int64) ([]*models.TokenRecord, error) {
func (s *TokenService) GetAllTokensByUid(c core.Context, uid int64) ([]*models.TokenRecord, error) {
if uid <= 0 {
return nil, errs.ErrUserIdInvalid
}
@@ -50,7 +50,7 @@ func (s *TokenService) GetAllTokensByUid(c *core.Context, uid int64) ([]*models.
}
// GetAllUnexpiredNormalTokensByUid returns all available token models of given user
func (s *TokenService) GetAllUnexpiredNormalTokensByUid(c *core.Context, uid int64) ([]*models.TokenRecord, error) {
func (s *TokenService) GetAllUnexpiredNormalTokensByUid(c core.Context, uid int64) ([]*models.TokenRecord, error) {
if uid <= 0 {
return nil, errs.ErrUserIdInvalid
}
@@ -64,42 +64,52 @@ func (s *TokenService) GetAllUnexpiredNormalTokensByUid(c *core.Context, uid int
}
// ParseTokenByHeader returns the token model according to request data
func (s *TokenService) ParseTokenByHeader(c *core.Context) (*jwt.Token, *core.UserTokenClaims, error) {
func (s *TokenService) ParseTokenByHeader(c *core.WebContext) (*jwt.Token, *core.UserTokenClaims, error) {
return s.parseToken(c, request.BearerExtractor{})
}
// ParseTokenByArgument returns the token model according to request data
func (s *TokenService) ParseTokenByArgument(c *core.Context, tokenParameterName string) (*jwt.Token, *core.UserTokenClaims, error) {
func (s *TokenService) ParseTokenByArgument(c *core.WebContext, tokenParameterName string) (*jwt.Token, *core.UserTokenClaims, error) {
return s.parseToken(c, request.ArgumentExtractor{tokenParameterName})
}
// ParseTokenByCookie returns the token model according to request data
func (s *TokenService) ParseTokenByCookie(c *core.Context, tokenCookieName string) (*jwt.Token, *core.UserTokenClaims, error) {
func (s *TokenService) ParseTokenByCookie(c *core.WebContext, tokenCookieName string) (*jwt.Token, *core.UserTokenClaims, error) {
return s.parseToken(c, utils.CookieExtractor{tokenCookieName})
}
// CreateToken generates a new normal token and saves to database
func (s *TokenService) CreateToken(c *core.Context, user *models.User) (string, *core.UserTokenClaims, error) {
func (s *TokenService) CreateToken(c *core.WebContext, user *models.User) (string, *core.UserTokenClaims, error) {
return s.createToken(c, user, core.USER_TOKEN_TYPE_NORMAL, s.getUserAgent(c), s.CurrentConfig().TokenExpiredTimeDuration)
}
// CreateRequire2FAToken generates a new token requiring user to verify 2fa passcode and saves to database
func (s *TokenService) CreateRequire2FAToken(c *core.Context, user *models.User) (string, *core.UserTokenClaims, error) {
func (s *TokenService) CreateRequire2FAToken(c *core.WebContext, user *models.User) (string, *core.UserTokenClaims, error) {
return s.createToken(c, user, core.USER_TOKEN_TYPE_REQUIRE_2FA, s.getUserAgent(c), s.CurrentConfig().TemporaryTokenExpiredTimeDuration)
}
// CreateEmailVerifyToken generates a new email verify token and saves to database
func (s *TokenService) CreateEmailVerifyToken(c *core.Context, user *models.User) (string, *core.UserTokenClaims, error) {
func (s *TokenService) CreateEmailVerifyToken(c *core.WebContext, user *models.User) (string, *core.UserTokenClaims, error) {
return s.createToken(c, user, core.USER_TOKEN_TYPE_EMAIL_VERIFY, s.getUserAgent(c), s.CurrentConfig().EmailVerifyTokenExpiredTimeDuration)
}
// CreateEmailVerifyTokenWithoutUserAgent generates a new email verify token and saves to database
func (s *TokenService) CreateEmailVerifyTokenWithoutUserAgent(c core.Context, user *models.User) (string, *core.UserTokenClaims, error) {
return s.createToken(c, user, core.USER_TOKEN_TYPE_EMAIL_VERIFY, "", s.CurrentConfig().EmailVerifyTokenExpiredTimeDuration)
}
// CreatePasswordResetToken generates a new password reset token and saves to database
func (s *TokenService) CreatePasswordResetToken(c *core.Context, user *models.User) (string, *core.UserTokenClaims, error) {
func (s *TokenService) CreatePasswordResetToken(c *core.WebContext, user *models.User) (string, *core.UserTokenClaims, error) {
return s.createToken(c, user, core.USER_TOKEN_TYPE_PASSWORD_RESET, s.getUserAgent(c), s.CurrentConfig().PasswordResetTokenExpiredTimeDuration)
}
// CreatePasswordResetTokenWithoutUserAgent generates a new password reset token and saves to database
func (s *TokenService) CreatePasswordResetTokenWithoutUserAgent(c core.Context, user *models.User) (string, *core.UserTokenClaims, error) {
return s.createToken(c, user, core.USER_TOKEN_TYPE_PASSWORD_RESET, "", s.CurrentConfig().PasswordResetTokenExpiredTimeDuration)
}
// UpdateTokenLastSeen updates the last seen time of specified token
func (s *TokenService) UpdateTokenLastSeen(c *core.Context, tokenRecord *models.TokenRecord) error {
func (s *TokenService) UpdateTokenLastSeen(c core.Context, tokenRecord *models.TokenRecord) error {
if tokenRecord.Uid <= 0 {
return errs.ErrUserIdInvalid
}
@@ -124,7 +134,7 @@ func (s *TokenService) UpdateTokenLastSeen(c *core.Context, tokenRecord *models.
}
// DeleteToken deletes given token from database
func (s *TokenService) DeleteToken(c *core.Context, tokenRecord *models.TokenRecord) error {
func (s *TokenService) DeleteToken(c core.Context, tokenRecord *models.TokenRecord) error {
if tokenRecord.Uid <= 0 {
return errs.ErrUserIdInvalid
}
@@ -147,7 +157,7 @@ func (s *TokenService) DeleteToken(c *core.Context, tokenRecord *models.TokenRec
}
// DeleteTokens deletes given tokens from database
func (s *TokenService) DeleteTokens(c *core.Context, uid int64, tokenRecords []*models.TokenRecord) error {
func (s *TokenService) DeleteTokens(c core.Context, uid int64, tokenRecords []*models.TokenRecord) error {
if uid <= 0 {
return errs.ErrUserIdInvalid
}
@@ -169,7 +179,7 @@ func (s *TokenService) DeleteTokens(c *core.Context, uid int64, tokenRecords []*
}
// DeleteTokenByClaims deletes given token from database
func (s *TokenService) DeleteTokenByClaims(c *core.Context, claims *core.UserTokenClaims) error {
func (s *TokenService) DeleteTokenByClaims(c core.Context, claims *core.UserTokenClaims) error {
userTokenId, err := utils.StringToInt64(claims.UserTokenId)
if err != nil {
@@ -184,7 +194,7 @@ func (s *TokenService) DeleteTokenByClaims(c *core.Context, claims *core.UserTok
}
// DeleteTokensBeforeTime deletes tokens that is created before specific time
func (s *TokenService) DeleteTokensBeforeTime(c *core.Context, uid int64, createTime int64) error {
func (s *TokenService) DeleteTokensBeforeTime(c core.Context, uid int64, createTime int64) error {
if uid <= 0 {
return errs.ErrUserIdInvalid
}
@@ -196,7 +206,7 @@ func (s *TokenService) DeleteTokensBeforeTime(c *core.Context, uid int64, create
}
// DeleteTokensByType deletes specified type tokens
func (s *TokenService) DeleteTokensByType(c *core.Context, uid int64, tokenType core.TokenType) error {
func (s *TokenService) DeleteTokensByType(c core.Context, uid int64, tokenType core.TokenType) error {
if uid <= 0 {
return errs.ErrUserIdInvalid
}
@@ -208,7 +218,7 @@ func (s *TokenService) DeleteTokensByType(c *core.Context, uid int64, tokenType
}
// DeleteAllExpiredTokens deletes all expired tokens
func (s *TokenService) DeleteAllExpiredTokens(c *core.Context) error {
func (s *TokenService) DeleteAllExpiredTokens(c core.Context) error {
var errors []error
totalCount := int64(0)
@@ -225,16 +235,16 @@ func (s *TokenService) DeleteAllExpiredTokens(c *core.Context) error {
}
if totalCount > 0 {
log.Infof("[tokens.DeleteAllExpiredTokens] %d expired tokens have been deleted", totalCount)
log.Infof(c, "[tokens.DeleteAllExpiredTokens] %d expired tokens have been deleted", totalCount)
} else if len(errors) == 0 {
log.Infof("[tokens.DeleteAllExpiredTokens] no expired tokens have been deleted")
log.Infof(c, "[tokens.DeleteAllExpiredTokens] no expired tokens have been deleted")
}
return errs.NewMultiErrorOrNil(errors...)
}
// ExistsValidTokenByType returns whether the given token type exists
func (s *TokenService) ExistsValidTokenByType(c *core.Context, uid int64, tokenType core.TokenType) (bool, error) {
func (s *TokenService) ExistsValidTokenByType(c core.Context, uid int64, tokenType core.TokenType) (bool, error) {
if uid <= 0 {
return false, errs.ErrUserIdInvalid
}
@@ -284,7 +294,7 @@ func (s *TokenService) GenerateTokenId(tokenRecord *models.TokenRecord) string {
return fmt.Sprintf("%d:%d:%d", tokenRecord.Uid, tokenRecord.CreatedUnixTime, tokenRecord.UserTokenId)
}
func (s *TokenService) parseToken(c *core.Context, extractor request.Extractor) (*jwt.Token, *core.UserTokenClaims, error) {
func (s *TokenService) parseToken(c *core.WebContext, extractor request.Extractor) (*jwt.Token, *core.UserTokenClaims, error) {
claims := &core.UserTokenClaims{}
token, err := request.ParseFromRequest(c.Request, extractor,
@@ -293,19 +303,19 @@ func (s *TokenService) parseToken(c *core.Context, extractor request.Extractor)
userTokenId, err := utils.StringToInt64(claims.UserTokenId)
if err != nil {
log.WarnfWithRequestId(c, "[tokens.ParseToken] token \"utid:%s\" in token of user \"uid:%d\" is invalid, because %s", claims.UserTokenId, claims.Uid, err.Error())
log.Warnf(c, "[tokens.ParseToken] token \"utid:%s\" in token of user \"uid:%d\" is invalid, because %s", claims.UserTokenId, claims.Uid, err.Error())
return nil, errs.ErrInvalidUserTokenId
}
tokenRecord, err := s.getTokenRecord(c, claims.Uid, userTokenId, claims.IssuedAt)
if err != nil {
log.WarnfWithRequestId(c, "[tokens.ParseToken] token \"utid:%s\" of user \"uid:%d\" record not found, because %s", claims.UserTokenId, claims.Uid, err.Error())
log.Warnf(c, "[tokens.ParseToken] token \"utid:%s\" of user \"uid:%d\" record not found, because %s", claims.UserTokenId, claims.Uid, err.Error())
return nil, errs.ErrTokenRecordNotFound
}
if tokenRecord.ExpiredUnixTime < now {
log.WarnfWithRequestId(c, "[tokens.ParseToken] token \"utid:%s\" of user \"uid:%d\" record is expired", claims.UserTokenId, claims.Uid)
log.Warnf(c, "[tokens.ParseToken] token \"utid:%s\" of user \"uid:%d\" record is expired", claims.UserTokenId, claims.Uid)
return nil, errs.ErrTokenExpired
}
@@ -321,7 +331,7 @@ func (s *TokenService) parseToken(c *core.Context, extractor request.Extractor)
}
if err == jwt.ErrTokenMalformed || err == jwt.ErrTokenUnverifiable || err == jwt.ErrTokenSignatureInvalid {
log.WarnfWithRequestId(c, "[tokens.ParseToken] token is invalid, because %s", err.Error())
log.Warnf(c, "[tokens.ParseToken] token is invalid, because %s", err.Error())
return nil, nil, errs.ErrCurrentInvalidToken
}
@@ -330,7 +340,7 @@ func (s *TokenService) parseToken(c *core.Context, extractor request.Extractor)
}
if err == jwt.ErrTokenUsedBeforeIssued {
log.WarnfWithRequestId(c, "[tokens.ParseToken] token is invalid, because issue time is later than now")
log.Warnf(c, "[tokens.ParseToken] token is invalid, because issue time is later than now")
return nil, nil, errs.ErrCurrentInvalidToken
}
@@ -340,7 +350,7 @@ func (s *TokenService) parseToken(c *core.Context, extractor request.Extractor)
return token, claims, err
}
func (s *TokenService) createToken(c *core.Context, user *models.User, tokenType core.TokenType, userAgent string, expiryDate time.Duration) (string, *core.UserTokenClaims, error) {
func (s *TokenService) createToken(c core.Context, user *models.User, tokenType core.TokenType, userAgent string, expiryDate time.Duration) (string, *core.UserTokenClaims, error) {
var err error
now := time.Now()
@@ -383,7 +393,7 @@ func (s *TokenService) createToken(c *core.Context, user *models.User, tokenType
return tokenString, claims, err
}
func (s *TokenService) getTokenRecord(c *core.Context, uid int64, userTokenId int64, createUnixTime int64) (*models.TokenRecord, error) {
func (s *TokenService) getTokenRecord(c core.Context, uid int64, userTokenId int64, createUnixTime int64) (*models.TokenRecord, error) {
if uid <= 0 {
return nil, errs.ErrUserIdInvalid
}
@@ -406,7 +416,7 @@ func (s *TokenService) getTokenRecord(c *core.Context, uid int64, userTokenId in
return tokenRecord, nil
}
func (s *TokenService) createTokenRecord(c *core.Context, tokenRecord *models.TokenRecord) error {
func (s *TokenService) createTokenRecord(c core.Context, tokenRecord *models.TokenRecord) error {
if tokenRecord.Uid <= 0 {
return errs.ErrUserIdInvalid
}
@@ -429,7 +439,7 @@ func (s *TokenService) getUserTokenId() int64 {
return userTokenId
}
func (s *TokenService) getUserAgent(ctx *core.Context) string {
func (s *TokenService) getUserAgent(ctx *core.WebContext) string {
userAgent := ""
if ctx != nil && ctx.Request != nil {
+14 -14
View File
@@ -32,7 +32,7 @@ var (
)
// GetTotalCategoryCountByUid returns total category count of user
func (s *TransactionCategoryService) GetTotalCategoryCountByUid(c *core.Context, uid int64) (int64, error) {
func (s *TransactionCategoryService) GetTotalCategoryCountByUid(c core.Context, uid int64) (int64, error) {
if uid <= 0 {
return 0, errs.ErrUserIdInvalid
}
@@ -43,7 +43,7 @@ func (s *TransactionCategoryService) GetTotalCategoryCountByUid(c *core.Context,
}
// GetAllCategoriesByUid returns all transaction category models of user
func (s *TransactionCategoryService) GetAllCategoriesByUid(c *core.Context, uid int64, categoryType models.TransactionCategoryType, parentCategoryId int64) ([]*models.TransactionCategory, error) {
func (s *TransactionCategoryService) GetAllCategoriesByUid(c core.Context, uid int64, categoryType models.TransactionCategoryType, parentCategoryId int64) ([]*models.TransactionCategory, error) {
if uid <= 0 {
return nil, errs.ErrUserIdInvalid
}
@@ -70,7 +70,7 @@ func (s *TransactionCategoryService) GetAllCategoriesByUid(c *core.Context, uid
}
// GetSubCategoriesByCategoryIds returns sub-category models according to category ids
func (s *TransactionCategoryService) GetSubCategoriesByCategoryIds(c *core.Context, uid int64, categoryIds []int64) ([]*models.TransactionCategory, error) {
func (s *TransactionCategoryService) GetSubCategoriesByCategoryIds(c core.Context, uid int64, categoryIds []int64) ([]*models.TransactionCategory, error) {
if uid <= 0 {
return nil, errs.ErrUserIdInvalid
}
@@ -112,7 +112,7 @@ func (s *TransactionCategoryService) GetSubCategoriesByCategoryIds(c *core.Conte
}
// GetCategoryByCategoryId returns a transaction category model according to transaction category id
func (s *TransactionCategoryService) GetCategoryByCategoryId(c *core.Context, uid int64, categoryId int64) (*models.TransactionCategory, error) {
func (s *TransactionCategoryService) GetCategoryByCategoryId(c core.Context, uid int64, categoryId int64) (*models.TransactionCategory, error) {
if uid <= 0 {
return nil, errs.ErrUserIdInvalid
}
@@ -134,7 +134,7 @@ func (s *TransactionCategoryService) GetCategoryByCategoryId(c *core.Context, ui
}
// GetCategoriesByCategoryIds returns transaction category models according to transaction category ids
func (s *TransactionCategoryService) GetCategoriesByCategoryIds(c *core.Context, uid int64, categoryIds []int64) (map[int64]*models.TransactionCategory, error) {
func (s *TransactionCategoryService) GetCategoriesByCategoryIds(c core.Context, uid int64, categoryIds []int64) (map[int64]*models.TransactionCategory, error) {
if uid <= 0 {
return nil, errs.ErrUserIdInvalid
}
@@ -155,7 +155,7 @@ func (s *TransactionCategoryService) GetCategoriesByCategoryIds(c *core.Context,
}
// GetMaxDisplayOrder returns the max display order according to transaction category type
func (s *TransactionCategoryService) GetMaxDisplayOrder(c *core.Context, uid int64, categoryType models.TransactionCategoryType) (int32, error) {
func (s *TransactionCategoryService) GetMaxDisplayOrder(c core.Context, uid int64, categoryType models.TransactionCategoryType) (int32, error) {
if uid <= 0 {
return 0, errs.ErrUserIdInvalid
}
@@ -175,7 +175,7 @@ func (s *TransactionCategoryService) GetMaxDisplayOrder(c *core.Context, uid int
}
// GetMaxSubCategoryDisplayOrder returns the max display order of sub transaction category according to transaction category type and parent transaction category id
func (s *TransactionCategoryService) GetMaxSubCategoryDisplayOrder(c *core.Context, uid int64, categoryType models.TransactionCategoryType, parentCategoryId int64) (int32, error) {
func (s *TransactionCategoryService) GetMaxSubCategoryDisplayOrder(c core.Context, uid int64, categoryType models.TransactionCategoryType, parentCategoryId int64) (int32, error) {
if uid <= 0 {
return 0, errs.ErrUserIdInvalid
}
@@ -199,7 +199,7 @@ func (s *TransactionCategoryService) GetMaxSubCategoryDisplayOrder(c *core.Conte
}
// CreateCategory saves a new transaction category model to database
func (s *TransactionCategoryService) CreateCategory(c *core.Context, category *models.TransactionCategory) error {
func (s *TransactionCategoryService) CreateCategory(c core.Context, category *models.TransactionCategory) error {
if category.Uid <= 0 {
return errs.ErrUserIdInvalid
}
@@ -221,7 +221,7 @@ func (s *TransactionCategoryService) CreateCategory(c *core.Context, category *m
}
// CreateCategories saves a few transaction category models to database
func (s *TransactionCategoryService) CreateCategories(c *core.Context, uid int64, categories map[*models.TransactionCategory][]*models.TransactionCategory) ([]*models.TransactionCategory, error) {
func (s *TransactionCategoryService) CreateCategories(c core.Context, uid int64, categories map[*models.TransactionCategory][]*models.TransactionCategory) ([]*models.TransactionCategory, error) {
if uid <= 0 {
return nil, errs.ErrUserIdInvalid
}
@@ -284,7 +284,7 @@ func (s *TransactionCategoryService) CreateCategories(c *core.Context, uid int64
}
// ModifyCategory saves an existed transaction category model to database
func (s *TransactionCategoryService) ModifyCategory(c *core.Context, category *models.TransactionCategory) error {
func (s *TransactionCategoryService) ModifyCategory(c core.Context, category *models.TransactionCategory) error {
if category.Uid <= 0 {
return errs.ErrUserIdInvalid
}
@@ -305,7 +305,7 @@ func (s *TransactionCategoryService) ModifyCategory(c *core.Context, category *m
}
// HideCategory updates hidden field of given transaction categories
func (s *TransactionCategoryService) HideCategory(c *core.Context, uid int64, ids []int64, hidden bool) error {
func (s *TransactionCategoryService) HideCategory(c core.Context, uid int64, ids []int64, hidden bool) error {
if uid <= 0 {
return errs.ErrUserIdInvalid
}
@@ -331,7 +331,7 @@ func (s *TransactionCategoryService) HideCategory(c *core.Context, uid int64, id
}
// ModifyCategoryDisplayOrders updates display order of given transaction categories
func (s *TransactionCategoryService) ModifyCategoryDisplayOrders(c *core.Context, uid int64, categories []*models.TransactionCategory) error {
func (s *TransactionCategoryService) ModifyCategoryDisplayOrders(c core.Context, uid int64, categories []*models.TransactionCategory) error {
if uid <= 0 {
return errs.ErrUserIdInvalid
}
@@ -357,7 +357,7 @@ func (s *TransactionCategoryService) ModifyCategoryDisplayOrders(c *core.Context
}
// DeleteCategory deletes an existed transaction category from database
func (s *TransactionCategoryService) DeleteCategory(c *core.Context, uid int64, categoryId int64) error {
func (s *TransactionCategoryService) DeleteCategory(c core.Context, uid int64, categoryId int64) error {
if uid <= 0 {
return errs.ErrUserIdInvalid
}
@@ -406,7 +406,7 @@ func (s *TransactionCategoryService) DeleteCategory(c *core.Context, uid int64,
}
// DeleteAllCategories deletes all existed transaction categories from database
func (s *TransactionCategoryService) DeleteAllCategories(c *core.Context, uid int64) error {
func (s *TransactionCategoryService) DeleteAllCategories(c core.Context, uid int64) error {
if uid <= 0 {
return errs.ErrUserIdInvalid
}
+16 -16
View File
@@ -33,7 +33,7 @@ var (
)
// GetTotalTagCountByUid returns total tag count of user
func (s *TransactionTagService) GetTotalTagCountByUid(c *core.Context, uid int64) (int64, error) {
func (s *TransactionTagService) GetTotalTagCountByUid(c core.Context, uid int64) (int64, error) {
if uid <= 0 {
return 0, errs.ErrUserIdInvalid
}
@@ -44,7 +44,7 @@ func (s *TransactionTagService) GetTotalTagCountByUid(c *core.Context, uid int64
}
// GetAllTagsByUid returns all transaction tag models of user
func (s *TransactionTagService) GetAllTagsByUid(c *core.Context, uid int64) ([]*models.TransactionTag, error) {
func (s *TransactionTagService) GetAllTagsByUid(c core.Context, uid int64) ([]*models.TransactionTag, error) {
if uid <= 0 {
return nil, errs.ErrUserIdInvalid
}
@@ -56,7 +56,7 @@ func (s *TransactionTagService) GetAllTagsByUid(c *core.Context, uid int64) ([]*
}
// GetTagByTagId returns a transaction tag model according to transaction tag id
func (s *TransactionTagService) GetTagByTagId(c *core.Context, uid int64, tagId int64) (*models.TransactionTag, error) {
func (s *TransactionTagService) GetTagByTagId(c core.Context, uid int64, tagId int64) (*models.TransactionTag, error) {
if uid <= 0 {
return nil, errs.ErrUserIdInvalid
}
@@ -78,7 +78,7 @@ func (s *TransactionTagService) GetTagByTagId(c *core.Context, uid int64, tagId
}
// GetTagsByTagIds returns transaction tag models according to transaction tag ids
func (s *TransactionTagService) GetTagsByTagIds(c *core.Context, uid int64, tagIds []int64) (map[int64]*models.TransactionTag, error) {
func (s *TransactionTagService) GetTagsByTagIds(c core.Context, uid int64, tagIds []int64) (map[int64]*models.TransactionTag, error) {
if uid <= 0 {
return nil, errs.ErrUserIdInvalid
}
@@ -99,7 +99,7 @@ func (s *TransactionTagService) GetTagsByTagIds(c *core.Context, uid int64, tagI
}
// GetMaxDisplayOrder returns the max display order
func (s *TransactionTagService) GetMaxDisplayOrder(c *core.Context, uid int64) (int32, error) {
func (s *TransactionTagService) GetMaxDisplayOrder(c core.Context, uid int64) (int32, error) {
if uid <= 0 {
return 0, errs.ErrUserIdInvalid
}
@@ -119,7 +119,7 @@ func (s *TransactionTagService) GetMaxDisplayOrder(c *core.Context, uid int64) (
}
// GetAllTagIdsOfAllTransactions returns all transaction tag ids
func (s *TransactionTagService) GetAllTagIdsOfAllTransactions(c *core.Context, uid int64) ([]*models.TransactionTagIndex, error) {
func (s *TransactionTagService) GetAllTagIdsOfAllTransactions(c core.Context, uid int64) ([]*models.TransactionTagIndex, error) {
if uid <= 0 {
return nil, errs.ErrUserIdInvalid
}
@@ -165,7 +165,7 @@ func (s *TransactionTagService) GetAllTagIdsOfAllTransactions(c *core.Context, u
}
// GetAllTagIdsMapOfAllTransactions returns all transaction tag ids map grouped by transaction id
func (s *TransactionTagService) GetAllTagIdsMapOfAllTransactions(c *core.Context, uid int64) (map[int64][]int64, error) {
func (s *TransactionTagService) GetAllTagIdsMapOfAllTransactions(c core.Context, uid int64) (map[int64][]int64, error) {
tagIndexes, err := s.GetAllTagIdsOfAllTransactions(c, uid)
if err != nil {
@@ -178,7 +178,7 @@ func (s *TransactionTagService) GetAllTagIdsMapOfAllTransactions(c *core.Context
}
// GetAllTagIdsOfTransactions returns transaction tag ids for given transactions
func (s *TransactionTagService) GetAllTagIdsOfTransactions(c *core.Context, uid int64, transactionIds []int64) (map[int64][]int64, error) {
func (s *TransactionTagService) GetAllTagIdsOfTransactions(c core.Context, uid int64, transactionIds []int64) (map[int64][]int64, error) {
if uid <= 0 {
return nil, errs.ErrUserIdInvalid
}
@@ -192,7 +192,7 @@ func (s *TransactionTagService) GetAllTagIdsOfTransactions(c *core.Context, uid
}
// CreateTag saves a new transaction tag model to database
func (s *TransactionTagService) CreateTag(c *core.Context, tag *models.TransactionTag) error {
func (s *TransactionTagService) CreateTag(c core.Context, tag *models.TransactionTag) error {
if tag.Uid <= 0 {
return errs.ErrUserIdInvalid
}
@@ -222,7 +222,7 @@ func (s *TransactionTagService) CreateTag(c *core.Context, tag *models.Transacti
}
// ModifyTag saves an existed transaction tag model to database
func (s *TransactionTagService) ModifyTag(c *core.Context, tag *models.TransactionTag) error {
func (s *TransactionTagService) ModifyTag(c core.Context, tag *models.TransactionTag) error {
if tag.Uid <= 0 {
return errs.ErrUserIdInvalid
}
@@ -251,7 +251,7 @@ func (s *TransactionTagService) ModifyTag(c *core.Context, tag *models.Transacti
}
// HideTag updates hidden field of given transaction tags
func (s *TransactionTagService) HideTag(c *core.Context, uid int64, ids []int64, hidden bool) error {
func (s *TransactionTagService) HideTag(c core.Context, uid int64, ids []int64, hidden bool) error {
if uid <= 0 {
return errs.ErrUserIdInvalid
}
@@ -277,7 +277,7 @@ func (s *TransactionTagService) HideTag(c *core.Context, uid int64, ids []int64,
}
// ModifyTagDisplayOrders updates display order of given transaction tags
func (s *TransactionTagService) ModifyTagDisplayOrders(c *core.Context, uid int64, tags []*models.TransactionTag) error {
func (s *TransactionTagService) ModifyTagDisplayOrders(c core.Context, uid int64, tags []*models.TransactionTag) error {
if uid <= 0 {
return errs.ErrUserIdInvalid
}
@@ -303,7 +303,7 @@ func (s *TransactionTagService) ModifyTagDisplayOrders(c *core.Context, uid int6
}
// DeleteTag deletes an existed transaction tag from database
func (s *TransactionTagService) DeleteTag(c *core.Context, uid int64, tagId int64) error {
func (s *TransactionTagService) DeleteTag(c core.Context, uid int64, tagId int64) error {
if uid <= 0 {
return errs.ErrUserIdInvalid
}
@@ -337,7 +337,7 @@ func (s *TransactionTagService) DeleteTag(c *core.Context, uid int64, tagId int6
}
// DeleteAllTags deletes all existed transaction tags from database
func (s *TransactionTagService) DeleteAllTags(c *core.Context, uid int64) error {
func (s *TransactionTagService) DeleteAllTags(c core.Context, uid int64) error {
if uid <= 0 {
return errs.ErrUserIdInvalid
}
@@ -369,7 +369,7 @@ func (s *TransactionTagService) DeleteAllTags(c *core.Context, uid int64) error
}
// ExistsTagName returns whether the given tag name exists
func (s *TransactionTagService) ExistsTagName(c *core.Context, uid int64, name string) (bool, error) {
func (s *TransactionTagService) ExistsTagName(c core.Context, uid int64, name string) (bool, error) {
if name == "" {
return false, errs.ErrTransactionTagNameIsEmpty
}
@@ -378,7 +378,7 @@ func (s *TransactionTagService) ExistsTagName(c *core.Context, uid int64, name s
}
// ModifyTagIndexTransactionTime updates transaction time of given transaction tag indexes
func (s *TransactionTagService) ModifyTagIndexTransactionTime(c *core.Context, uid int64, tagIndexes []*models.TransactionTagIndex) error {
func (s *TransactionTagService) ModifyTagIndexTransactionTime(c core.Context, uid int64, tagIndexes []*models.TransactionTagIndex) error {
if uid <= 0 {
return errs.ErrUserIdInvalid
}
+10 -10
View File
@@ -30,7 +30,7 @@ var (
)
// GetTotalNormalTemplateCountByUid returns total template count of user
func (s *TransactionTemplateService) GetTotalNormalTemplateCountByUid(c *core.Context, uid int64) (int64, error) {
func (s *TransactionTemplateService) GetTotalNormalTemplateCountByUid(c core.Context, uid int64) (int64, error) {
if uid <= 0 {
return 0, errs.ErrUserIdInvalid
}
@@ -41,7 +41,7 @@ func (s *TransactionTemplateService) GetTotalNormalTemplateCountByUid(c *core.Co
}
// GetAllTemplatesByUid returns all transaction template models of user
func (s *TransactionTemplateService) GetAllTemplatesByUid(c *core.Context, uid int64, templateType models.TransactionTemplateType) ([]*models.TransactionTemplate, error) {
func (s *TransactionTemplateService) GetAllTemplatesByUid(c core.Context, uid int64, templateType models.TransactionTemplateType) ([]*models.TransactionTemplate, error) {
if uid <= 0 {
return nil, errs.ErrUserIdInvalid
}
@@ -53,7 +53,7 @@ func (s *TransactionTemplateService) GetAllTemplatesByUid(c *core.Context, uid i
}
// GetTemplateByTemplateId returns a transaction template model according to transaction template id
func (s *TransactionTemplateService) GetTemplateByTemplateId(c *core.Context, uid int64, templateId int64) (*models.TransactionTemplate, error) {
func (s *TransactionTemplateService) GetTemplateByTemplateId(c core.Context, uid int64, templateId int64) (*models.TransactionTemplate, error) {
if uid <= 0 {
return nil, errs.ErrUserIdInvalid
}
@@ -75,7 +75,7 @@ func (s *TransactionTemplateService) GetTemplateByTemplateId(c *core.Context, ui
}
// GetMaxDisplayOrder returns the max display order
func (s *TransactionTemplateService) GetMaxDisplayOrder(c *core.Context, uid int64, templateType models.TransactionTemplateType) (int32, error) {
func (s *TransactionTemplateService) GetMaxDisplayOrder(c core.Context, uid int64, templateType models.TransactionTemplateType) (int32, error) {
if uid <= 0 {
return 0, errs.ErrUserIdInvalid
}
@@ -95,7 +95,7 @@ func (s *TransactionTemplateService) GetMaxDisplayOrder(c *core.Context, uid int
}
// CreateTemplate saves a new transaction template model to database
func (s *TransactionTemplateService) CreateTemplate(c *core.Context, template *models.TransactionTemplate) error {
func (s *TransactionTemplateService) CreateTemplate(c core.Context, template *models.TransactionTemplate) error {
if template.Uid <= 0 {
return errs.ErrUserIdInvalid
}
@@ -117,7 +117,7 @@ func (s *TransactionTemplateService) CreateTemplate(c *core.Context, template *m
}
// ModifyTemplate saves an existed transaction template model to database
func (s *TransactionTemplateService) ModifyTemplate(c *core.Context, template *models.TransactionTemplate) error {
func (s *TransactionTemplateService) ModifyTemplate(c core.Context, template *models.TransactionTemplate) error {
if template.Uid <= 0 {
return errs.ErrUserIdInvalid
}
@@ -138,7 +138,7 @@ func (s *TransactionTemplateService) ModifyTemplate(c *core.Context, template *m
}
// HideTemplate updates hidden field of given transaction templates
func (s *TransactionTemplateService) HideTemplate(c *core.Context, uid int64, ids []int64, hidden bool) error {
func (s *TransactionTemplateService) HideTemplate(c core.Context, uid int64, ids []int64, hidden bool) error {
if uid <= 0 {
return errs.ErrUserIdInvalid
}
@@ -164,7 +164,7 @@ func (s *TransactionTemplateService) HideTemplate(c *core.Context, uid int64, id
}
// ModifyTemplateDisplayOrders updates display order of given transaction templates
func (s *TransactionTemplateService) ModifyTemplateDisplayOrders(c *core.Context, uid int64, templates []*models.TransactionTemplate) error {
func (s *TransactionTemplateService) ModifyTemplateDisplayOrders(c core.Context, uid int64, templates []*models.TransactionTemplate) error {
if uid <= 0 {
return errs.ErrUserIdInvalid
}
@@ -190,7 +190,7 @@ func (s *TransactionTemplateService) ModifyTemplateDisplayOrders(c *core.Context
}
// DeleteTemplate deletes an existed transaction template from database
func (s *TransactionTemplateService) DeleteTemplate(c *core.Context, uid int64, templateId int64) error {
func (s *TransactionTemplateService) DeleteTemplate(c core.Context, uid int64, templateId int64) error {
if uid <= 0 {
return errs.ErrUserIdInvalid
}
@@ -216,7 +216,7 @@ func (s *TransactionTemplateService) DeleteTemplate(c *core.Context, uid int64,
}
// DeleteAllTemplates deletes all existed transaction templates from database
func (s *TransactionTemplateService) DeleteAllTemplates(c *core.Context, uid int64) error {
func (s *TransactionTemplateService) DeleteAllTemplates(c core.Context, uid int64) error {
if uid <= 0 {
return errs.ErrUserIdInvalid
}
+15 -15
View File
@@ -37,7 +37,7 @@ var (
)
// GetTotalTransactionCountByUid returns total transaction count of user
func (s *TransactionService) GetTotalTransactionCountByUid(c *core.Context, uid int64) (int64, error) {
func (s *TransactionService) GetTotalTransactionCountByUid(c core.Context, uid int64) (int64, error) {
if uid <= 0 {
return 0, errs.ErrUserIdInvalid
}
@@ -48,7 +48,7 @@ func (s *TransactionService) GetTotalTransactionCountByUid(c *core.Context, uid
}
// GetAllTransactions returns all transactions
func (s *TransactionService) GetAllTransactions(c *core.Context, uid int64, pageCount int32, noDuplicated bool) ([]*models.Transaction, error) {
func (s *TransactionService) GetAllTransactions(c core.Context, uid int64, pageCount int32, noDuplicated bool) ([]*models.Transaction, error) {
maxTransactionTime := utils.GetMaxTransactionTimeFromUnixTime(time.Now().Unix())
var allTransactions []*models.Transaction
@@ -73,12 +73,12 @@ func (s *TransactionService) GetAllTransactions(c *core.Context, uid int64, page
}
// GetAllTransactionsByMaxTime returns all transactions before given time
func (s *TransactionService) GetAllTransactionsByMaxTime(c *core.Context, uid int64, maxTransactionTime int64, count int32, noDuplicated bool) ([]*models.Transaction, error) {
func (s *TransactionService) GetAllTransactionsByMaxTime(c core.Context, uid int64, maxTransactionTime int64, count int32, noDuplicated bool) ([]*models.Transaction, error) {
return s.GetTransactionsByMaxTime(c, uid, maxTransactionTime, 0, 0, nil, nil, nil, false, "", "", 1, count, false, noDuplicated)
}
// GetTransactionsByMaxTime returns transactions before given time
func (s *TransactionService) GetTransactionsByMaxTime(c *core.Context, uid int64, maxTransactionTime int64, minTransactionTime int64, transactionType models.TransactionDbType, categoryIds []int64, accountIds []int64, tagIds []int64, noTags bool, amountFilter string, keyword string, page int32, count int32, needOneMoreItem bool, noDuplicated bool) ([]*models.Transaction, error) {
func (s *TransactionService) GetTransactionsByMaxTime(c core.Context, uid int64, maxTransactionTime int64, minTransactionTime int64, transactionType models.TransactionDbType, categoryIds []int64, accountIds []int64, tagIds []int64, noTags bool, amountFilter string, keyword string, page int32, count int32, needOneMoreItem bool, noDuplicated bool) ([]*models.Transaction, error) {
if uid <= 0 {
return nil, errs.ErrUserIdInvalid
}
@@ -117,7 +117,7 @@ func (s *TransactionService) GetTransactionsByMaxTime(c *core.Context, uid int64
}
// GetTransactionsInMonthByPage returns all transactions in given year and month
func (s *TransactionService) GetTransactionsInMonthByPage(c *core.Context, uid int64, year int32, month int32, transactionType models.TransactionDbType, categoryIds []int64, accountIds []int64, tagIds []int64, noTags bool, amountFilter string, keyword string) ([]*models.Transaction, error) {
func (s *TransactionService) GetTransactionsInMonthByPage(c core.Context, uid int64, year int32, month int32, transactionType models.TransactionDbType, categoryIds []int64, accountIds []int64, tagIds []int64, noTags bool, amountFilter string, keyword string) ([]*models.Transaction, error) {
if uid <= 0 {
return nil, errs.ErrUserIdInvalid
}
@@ -157,7 +157,7 @@ func (s *TransactionService) GetTransactionsInMonthByPage(c *core.Context, uid i
}
// GetTransactionByTransactionId returns a transaction model according to transaction id
func (s *TransactionService) GetTransactionByTransactionId(c *core.Context, uid int64, transactionId int64) (*models.Transaction, error) {
func (s *TransactionService) GetTransactionByTransactionId(c core.Context, uid int64, transactionId int64) (*models.Transaction, error) {
if uid <= 0 {
return nil, errs.ErrUserIdInvalid
}
@@ -179,12 +179,12 @@ func (s *TransactionService) GetTransactionByTransactionId(c *core.Context, uid
}
// GetAllTransactionCount returns total count of transactions
func (s *TransactionService) GetAllTransactionCount(c *core.Context, uid int64) (int64, error) {
func (s *TransactionService) GetAllTransactionCount(c core.Context, uid int64) (int64, error) {
return s.GetTransactionCount(c, uid, 0, 0, 0, nil, nil, nil, false, "", "")
}
// GetTransactionCount returns count of transactions
func (s *TransactionService) GetTransactionCount(c *core.Context, uid int64, maxTransactionTime int64, minTransactionTime int64, transactionType models.TransactionDbType, categoryIds []int64, accountIds []int64, tagIds []int64, noTags bool, amountFilter string, keyword string) (int64, error) {
func (s *TransactionService) GetTransactionCount(c core.Context, uid int64, maxTransactionTime int64, minTransactionTime int64, transactionType models.TransactionDbType, categoryIds []int64, accountIds []int64, tagIds []int64, noTags bool, amountFilter string, keyword string) (int64, error) {
if uid <= 0 {
return 0, errs.ErrUserIdInvalid
}
@@ -202,7 +202,7 @@ func (s *TransactionService) GetTransactionCount(c *core.Context, uid int64, max
}
// CreateTransaction saves a new transaction to database
func (s *TransactionService) CreateTransaction(c *core.Context, transaction *models.Transaction, tagIds []int64) error {
func (s *TransactionService) CreateTransaction(c core.Context, transaction *models.Transaction, tagIds []int64) error {
if transaction.Uid <= 0 {
return errs.ErrUserIdInvalid
}
@@ -430,7 +430,7 @@ func (s *TransactionService) CreateTransaction(c *core.Context, transaction *mod
}
// ModifyTransaction saves an existed transaction to database
func (s *TransactionService) ModifyTransaction(c *core.Context, transaction *models.Transaction, currentTagIdsCount int, addTagIds []int64, removeTagIds []int64) error {
func (s *TransactionService) ModifyTransaction(c core.Context, transaction *models.Transaction, currentTagIdsCount int, addTagIds []int64, removeTagIds []int64) error {
if transaction.Uid <= 0 {
return errs.ErrUserIdInvalid
}
@@ -826,7 +826,7 @@ func (s *TransactionService) ModifyTransaction(c *core.Context, transaction *mod
}
// DeleteTransaction deletes an existed transaction from database
func (s *TransactionService) DeleteTransaction(c *core.Context, uid int64, transactionId int64) error {
func (s *TransactionService) DeleteTransaction(c core.Context, uid int64, transactionId int64) error {
if uid <= 0 {
return errs.ErrUserIdInvalid
}
@@ -950,7 +950,7 @@ func (s *TransactionService) DeleteTransaction(c *core.Context, uid int64, trans
}
// DeleteAllTransactions deletes all existed transactions from database
func (s *TransactionService) DeleteAllTransactions(c *core.Context, uid int64) error {
func (s *TransactionService) DeleteAllTransactions(c core.Context, uid int64) error {
if uid <= 0 {
return errs.ErrUserIdInvalid
}
@@ -1040,7 +1040,7 @@ func (s *TransactionService) GetRelatedTransferTransaction(originalTransaction *
}
// GetAccountsTotalIncomeAndExpense returns the every accounts total income and expense amount by specific date range
func (s *TransactionService) GetAccountsTotalIncomeAndExpense(c *core.Context, uid int64, startUnixTime int64, endUnixTime int64, utcOffset int16, useTransactionTimezone bool) (map[int64]int64, map[int64]int64, error) {
func (s *TransactionService) GetAccountsTotalIncomeAndExpense(c core.Context, uid int64, startUnixTime int64, endUnixTime int64, utcOffset int16, useTransactionTimezone bool) (map[int64]int64, map[int64]int64, error) {
if uid <= 0 {
return nil, nil, errs.ErrUserIdInvalid
}
@@ -1129,7 +1129,7 @@ func (s *TransactionService) GetAccountsTotalIncomeAndExpense(c *core.Context, u
}
// GetAccountsAndCategoriesTotalIncomeAndExpense returns the every accounts and categories total income and expense amount by specific date range
func (s *TransactionService) GetAccountsAndCategoriesTotalIncomeAndExpense(c *core.Context, uid int64, startUnixTime int64, endUnixTime int64, utcOffset int16, useTransactionTimezone bool) ([]*models.Transaction, error) {
func (s *TransactionService) GetAccountsAndCategoriesTotalIncomeAndExpense(c core.Context, uid int64, startUnixTime int64, endUnixTime int64, utcOffset int16, useTransactionTimezone bool) ([]*models.Transaction, error) {
if uid <= 0 {
return nil, errs.ErrUserIdInvalid
}
@@ -1235,7 +1235,7 @@ func (s *TransactionService) GetAccountsAndCategoriesTotalIncomeAndExpense(c *co
}
// GetAccountsAndCategoriesMonthlyIncomeAndExpense returns the every accounts monthly income and expense amount by specific date range
func (s *TransactionService) GetAccountsAndCategoriesMonthlyIncomeAndExpense(c *core.Context, uid int64, startYear int32, startMonth int32, endYear int32, endMonth int32, utcOffset int16, useTransactionTimezone bool) (map[int32][]*models.Transaction, error) {
func (s *TransactionService) GetAccountsAndCategoriesMonthlyIncomeAndExpense(c core.Context, uid int64, startYear int32, startMonth int32, endYear int32, endMonth int32, utcOffset int16, useTransactionTimezone bool) (map[int32][]*models.Transaction, error) {
if uid <= 0 {
return nil, errs.ErrUserIdInvalid
}
+8 -8
View File
@@ -46,7 +46,7 @@ var (
)
// GetUserTwoFactorSettingByUid returns the 2fa setting model according to user uid
func (s *TwoFactorAuthorizationService) GetUserTwoFactorSettingByUid(c *core.Context, uid int64) (*models.TwoFactor, error) {
func (s *TwoFactorAuthorizationService) GetUserTwoFactorSettingByUid(c core.Context, uid int64) (*models.TwoFactor, error) {
if uid <= 0 {
return nil, errs.ErrUserIdInvalid
}
@@ -70,7 +70,7 @@ func (s *TwoFactorAuthorizationService) GetUserTwoFactorSettingByUid(c *core.Con
}
// GenerateTwoFactorSecret generates a new 2fa secret
func (s *TwoFactorAuthorizationService) GenerateTwoFactorSecret(c *core.Context, user *models.User) (*otp.Key, error) {
func (s *TwoFactorAuthorizationService) GenerateTwoFactorSecret(c core.Context, user *models.User) (*otp.Key, error) {
if user == nil {
return nil, errs.ErrUserNotFound
}
@@ -86,7 +86,7 @@ func (s *TwoFactorAuthorizationService) GenerateTwoFactorSecret(c *core.Context,
}
// CreateTwoFactorSetting saves a new 2fa setting to database
func (s *TwoFactorAuthorizationService) CreateTwoFactorSetting(c *core.Context, twoFactor *models.TwoFactor) error {
func (s *TwoFactorAuthorizationService) CreateTwoFactorSetting(c core.Context, twoFactor *models.TwoFactor) error {
if twoFactor.Uid <= 0 {
return errs.ErrUserIdInvalid
}
@@ -107,7 +107,7 @@ func (s *TwoFactorAuthorizationService) CreateTwoFactorSetting(c *core.Context,
}
// DeleteTwoFactorSetting deletes an existed 2fa setting from database
func (s *TwoFactorAuthorizationService) DeleteTwoFactorSetting(c *core.Context, uid int64) error {
func (s *TwoFactorAuthorizationService) DeleteTwoFactorSetting(c core.Context, uid int64) error {
if uid <= 0 {
return errs.ErrUserIdInvalid
}
@@ -126,7 +126,7 @@ func (s *TwoFactorAuthorizationService) DeleteTwoFactorSetting(c *core.Context,
}
// ExistsTwoFactorSetting returns whether the given user has existed 2fa setting
func (s *TwoFactorAuthorizationService) ExistsTwoFactorSetting(c *core.Context, uid int64) (bool, error) {
func (s *TwoFactorAuthorizationService) ExistsTwoFactorSetting(c core.Context, uid int64) (bool, error) {
if uid <= 0 {
return false, errs.ErrUserIdInvalid
}
@@ -135,7 +135,7 @@ func (s *TwoFactorAuthorizationService) ExistsTwoFactorSetting(c *core.Context,
}
// GetAndUseUserTwoFactorRecoveryCode checks whether the given 2fa recovery code exists and marks it used
func (s *TwoFactorAuthorizationService) GetAndUseUserTwoFactorRecoveryCode(c *core.Context, uid int64, recoveryCode string, salt string) error {
func (s *TwoFactorAuthorizationService) GetAndUseUserTwoFactorRecoveryCode(c core.Context, uid int64, recoveryCode string, salt string) error {
if uid <= 0 {
return errs.ErrUserIdInvalid
}
@@ -173,7 +173,7 @@ func (s *TwoFactorAuthorizationService) GenerateTwoFactorRecoveryCodes() ([]stri
}
// CreateTwoFactorRecoveryCodes saves new 2fa recovery codes to database
func (s *TwoFactorAuthorizationService) CreateTwoFactorRecoveryCodes(c *core.Context, uid int64, recoveryCodes []string, salt string) error {
func (s *TwoFactorAuthorizationService) CreateTwoFactorRecoveryCodes(c core.Context, uid int64, recoveryCodes []string, salt string) error {
twoFactorRecoveryCodes := make([]*models.TwoFactorRecoveryCode, len(recoveryCodes))
for i := 0; i < len(recoveryCodes); i++ {
@@ -206,7 +206,7 @@ func (s *TwoFactorAuthorizationService) CreateTwoFactorRecoveryCodes(c *core.Con
}
// DeleteTwoFactorRecoveryCodes deletes existed 2fa recovery codes from database
func (s *TwoFactorAuthorizationService) DeleteTwoFactorRecoveryCodes(c *core.Context, uid int64) error {
func (s *TwoFactorAuthorizationService) DeleteTwoFactorRecoveryCodes(c core.Context, uid int64) error {
if uid <= 0 {
return errs.ErrUserIdInvalid
}
+18 -18
View File
@@ -58,7 +58,7 @@ var (
)
// GetUserByUsernameOrEmailAndPassword returns the user model according to login name and password
func (s *UserService) GetUserByUsernameOrEmailAndPassword(c *core.Context, loginname string, password string) (*models.User, error) {
func (s *UserService) GetUserByUsernameOrEmailAndPassword(c core.Context, loginname string, password string) (*models.User, error) {
var user *models.User
var err error
@@ -82,7 +82,7 @@ func (s *UserService) GetUserByUsernameOrEmailAndPassword(c *core.Context, login
}
// GetUserById returns the user model according to user uid
func (s *UserService) GetUserById(c *core.Context, uid int64) (*models.User, error) {
func (s *UserService) GetUserById(c core.Context, uid int64) (*models.User, error) {
if uid <= 0 {
return nil, errs.ErrUserIdInvalid
}
@@ -100,7 +100,7 @@ func (s *UserService) GetUserById(c *core.Context, uid int64) (*models.User, err
}
// GetUserByUsername returns the user model according to user name
func (s *UserService) GetUserByUsername(c *core.Context, username string) (*models.User, error) {
func (s *UserService) GetUserByUsername(c core.Context, username string) (*models.User, error) {
if username == "" {
return nil, errs.ErrUsernameIsEmpty
}
@@ -118,7 +118,7 @@ func (s *UserService) GetUserByUsername(c *core.Context, username string) (*mode
}
// GetUserByEmail returns the user model according to user email
func (s *UserService) GetUserByEmail(c *core.Context, email string) (*models.User, error) {
func (s *UserService) GetUserByEmail(c core.Context, email string) (*models.User, error) {
if email == "" {
return nil, errs.ErrEmailIsEmpty
}
@@ -136,7 +136,7 @@ func (s *UserService) GetUserByEmail(c *core.Context, email string) (*models.Use
}
// GetUserAvatar returns the user avatar image data and image file extension according to user uid
func (s *UserService) GetUserAvatar(c *core.Context, uid int64, fileExtension string) ([]byte, error) {
func (s *UserService) GetUserAvatar(c core.Context, uid int64, fileExtension string) ([]byte, error) {
if uid <= 0 {
return nil, errs.ErrUserIdInvalid
}
@@ -180,7 +180,7 @@ func (s *UserService) GetUserAvatar(c *core.Context, uid int64, fileExtension st
}
// CreateUser saves a new user model to database
func (s *UserService) CreateUser(c *core.Context, user *models.User) error {
func (s *UserService) CreateUser(c core.Context, user *models.User) error {
exists, err := s.ExistsUsername(c, user.Username)
if err != nil {
@@ -226,7 +226,7 @@ func (s *UserService) CreateUser(c *core.Context, user *models.User) error {
}
// UpdateUser saves an existed user model to database
func (s *UserService) UpdateUser(c *core.Context, user *models.User, modifyUserLanguage bool) (keyProfileUpdated bool, emailSetToUnverified bool, err error) {
func (s *UserService) UpdateUser(c core.Context, user *models.User, modifyUserLanguage bool) (keyProfileUpdated bool, emailSetToUnverified bool, err error) {
if user.Uid <= 0 {
return false, false, errs.ErrUserIdInvalid
}
@@ -348,7 +348,7 @@ func (s *UserService) UpdateUser(c *core.Context, user *models.User, modifyUserL
}
// UpdateUserAvatar updates the custom avatar type of specified user
func (s *UserService) UpdateUserAvatar(c *core.Context, uid int64, avatarFile multipart.File, fileExtension string, oldFileExtension string) error {
func (s *UserService) UpdateUserAvatar(c core.Context, uid int64, avatarFile multipart.File, fileExtension string, oldFileExtension string) error {
if uid <= 0 {
return errs.ErrUserIdInvalid
}
@@ -381,7 +381,7 @@ func (s *UserService) UpdateUserAvatar(c *core.Context, uid int64, avatarFile mu
err = s.DeleteAvatar(uid, oldFileExtension)
if err != nil {
log.WarnfWithRequestId(c, "[users.UpdateUserAvatar] failed to delete old avatar with extension \"%s\" for user \"uid:%d\", because %s", oldFileExtension, uid, err.Error())
log.Warnf(c, "[users.UpdateUserAvatar] failed to delete old avatar with extension \"%s\" for user \"uid:%d\", because %s", oldFileExtension, uid, err.Error())
}
}
@@ -389,7 +389,7 @@ func (s *UserService) UpdateUserAvatar(c *core.Context, uid int64, avatarFile mu
}
// RemoveUserAvatar removes the custom avatar type of specified user
func (s *UserService) RemoveUserAvatar(c *core.Context, uid int64, fileExtension string) error {
func (s *UserService) RemoveUserAvatar(c core.Context, uid int64, fileExtension string) error {
if uid <= 0 {
return errs.ErrUserIdInvalid
}
@@ -414,7 +414,7 @@ func (s *UserService) RemoveUserAvatar(c *core.Context, uid int64, fileExtension
}
// UpdateUserLastLoginTime updates the last login time field
func (s *UserService) UpdateUserLastLoginTime(c *core.Context, uid int64) error {
func (s *UserService) UpdateUserLastLoginTime(c core.Context, uid int64) error {
if uid <= 0 {
return errs.ErrUserIdInvalid
}
@@ -426,7 +426,7 @@ func (s *UserService) UpdateUserLastLoginTime(c *core.Context, uid int64) error
}
// EnableUser sets user enabled
func (s *UserService) EnableUser(c *core.Context, username string) error {
func (s *UserService) EnableUser(c core.Context, username string) error {
if username == "" {
return errs.ErrUsernameIsEmpty
}
@@ -449,7 +449,7 @@ func (s *UserService) EnableUser(c *core.Context, username string) error {
}
// DisableUser sets user disabled
func (s *UserService) DisableUser(c *core.Context, username string) error {
func (s *UserService) DisableUser(c core.Context, username string) error {
if username == "" {
return errs.ErrUsernameIsEmpty
}
@@ -472,7 +472,7 @@ func (s *UserService) DisableUser(c *core.Context, username string) error {
}
// SetUserEmailVerified sets user email address verified
func (s *UserService) SetUserEmailVerified(c *core.Context, username string) error {
func (s *UserService) SetUserEmailVerified(c core.Context, username string) error {
if username == "" {
return errs.ErrUsernameIsEmpty
}
@@ -495,7 +495,7 @@ func (s *UserService) SetUserEmailVerified(c *core.Context, username string) err
}
// SetUserEmailUnverified sets user email address unverified
func (s *UserService) SetUserEmailUnverified(c *core.Context, username string) error {
func (s *UserService) SetUserEmailUnverified(c core.Context, username string) error {
if username == "" {
return errs.ErrUsernameIsEmpty
}
@@ -518,7 +518,7 @@ func (s *UserService) SetUserEmailUnverified(c *core.Context, username string) e
}
// DeleteUser deletes an existed user from database
func (s *UserService) DeleteUser(c *core.Context, username string) error {
func (s *UserService) DeleteUser(c core.Context, username string) error {
if username == "" {
return errs.ErrUsernameIsEmpty
}
@@ -541,7 +541,7 @@ func (s *UserService) DeleteUser(c *core.Context, username string) error {
}
// ExistsUsername returns whether the given user name exists
func (s *UserService) ExistsUsername(c *core.Context, username string) (bool, error) {
func (s *UserService) ExistsUsername(c core.Context, username string) (bool, error) {
if username == "" {
return false, errs.ErrUsernameIsEmpty
}
@@ -550,7 +550,7 @@ func (s *UserService) ExistsUsername(c *core.Context, username string) (bool, er
}
// ExistsEmail returns whether the given user email exists
func (s *UserService) ExistsEmail(c *core.Context, email string) (bool, error) {
func (s *UserService) ExistsEmail(c core.Context, email string) (bool, error) {
if email == "" {
return false, errs.ErrEmailIsEmpty
}