format code
This commit is contained in:
@@ -187,10 +187,10 @@ func (a *AuthorizationsApi) TwoFactorAuthorizeByRecoveryCodeHandler(c *core.Cont
|
||||
return authResp, nil
|
||||
}
|
||||
|
||||
func (a *AuthorizationsApi) getAuthResponse(token string, need2FA bool, user *models.User) (*models.AuthResponse) {
|
||||
func (a *AuthorizationsApi) getAuthResponse(token string, need2FA bool, user *models.User) *models.AuthResponse {
|
||||
return &models.AuthResponse{
|
||||
Token : token,
|
||||
Token: token,
|
||||
Need2FA: need2FA,
|
||||
User: user.ToUserBasicInfo(),
|
||||
User: user.ToUserBasicInfo(),
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ import (
|
||||
"github.com/mayswind/lab/pkg/errs"
|
||||
)
|
||||
|
||||
type DefaultApi struct {}
|
||||
type DefaultApi struct{}
|
||||
|
||||
var (
|
||||
Default = &DefaultApi{}
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
|
||||
const EuroCentralBankExchangeRateUrl = "https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml"
|
||||
|
||||
type ExchangeRatesApi struct {}
|
||||
type ExchangeRatesApi struct{}
|
||||
|
||||
var (
|
||||
ExchangeRates = &ExchangeRatesApi{}
|
||||
@@ -52,7 +52,7 @@ func (a *ExchangeRatesApi) LatestExchangeRateHandler(c *core.Context) (interface
|
||||
|
||||
latestExchangeRateResponse.ExchangeRates = append(latestExchangeRateResponse.ExchangeRates, &models.LatestExchangeRate{
|
||||
Currency: "EUR",
|
||||
Rate: "1",
|
||||
Rate: "1",
|
||||
})
|
||||
|
||||
return latestExchangeRateResponse, nil
|
||||
|
||||
@@ -156,9 +156,9 @@ func (a *TransactionCategoriesApi) CategoryCreateBatchHandler(c *core.Context) (
|
||||
}
|
||||
|
||||
category := a.createNewCategoryModel(uid, &models.TransactionCategoryCreateRequest{
|
||||
Name: categoryCreateReq.Name,
|
||||
Type: categoryCreateReq.Type,
|
||||
Icon: categoryCreateReq.Icon,
|
||||
Name: categoryCreateReq.Name,
|
||||
Type: categoryCreateReq.Type,
|
||||
Icon: categoryCreateReq.Icon,
|
||||
Color: categoryCreateReq.Color,
|
||||
}, maxOrderId+1)
|
||||
|
||||
@@ -171,7 +171,7 @@ func (a *TransactionCategoriesApi) CategoryCreateBatchHandler(c *core.Context) (
|
||||
}
|
||||
|
||||
categoriesMap[nil][i] = category
|
||||
categoryTypeMaxOrderMap[categoryCreateReq.Type] = maxOrderId+1
|
||||
categoryTypeMaxOrderMap[categoryCreateReq.Type] = maxOrderId + 1
|
||||
totalCount++
|
||||
}
|
||||
|
||||
|
||||
@@ -114,9 +114,9 @@ func (a *TransactionTagsApi) TagModifyHandler(c *core.Context) (interface{}, *er
|
||||
}
|
||||
|
||||
newTag := &models.TransactionTag{
|
||||
TagId: tag.TagId,
|
||||
Uid: uid,
|
||||
Name: tagModifyReq.Name,
|
||||
TagId: tag.TagId,
|
||||
Uid: uid,
|
||||
Name: tagModifyReq.Name,
|
||||
}
|
||||
|
||||
if newTag.Name == tag.Name {
|
||||
|
||||
@@ -33,7 +33,7 @@ func (a *TransactionsApi) TransactionListHandler(c *core.Context) (interface{},
|
||||
}
|
||||
|
||||
uid := c.GetCurrentUid()
|
||||
transactions, err := a.transactions.GetTransactionsByMaxTime(uid, transactionListReq.MaxTime, transactionListReq.Count + 1)
|
||||
transactions, err := a.transactions.GetTransactionsByMaxTime(uid, transactionListReq.MaxTime, transactionListReq.Count+1)
|
||||
|
||||
if err != nil {
|
||||
log.ErrorfWithRequestId(c, "[transactions.TransactionListHandler] failed to get transactions earlier than \"%d\" for user \"uid:%d\", because %s", transactionListReq.MaxTime, uid, err.Error())
|
||||
@@ -236,7 +236,7 @@ func (a *TransactionsApi) TransactionModifyHandler(c *core.Context) (interface{}
|
||||
}
|
||||
|
||||
if newTransaction.CategoryId == transaction.CategoryId &&
|
||||
newTransaction.TransactionTime / 1000 == transaction.TransactionTime / 1000 &&
|
||||
newTransaction.TransactionTime/1000 == transaction.TransactionTime/1000 &&
|
||||
newTransaction.SourceAccountId == transaction.SourceAccountId &&
|
||||
newTransaction.DestinationAccountId == transaction.DestinationAccountId &&
|
||||
newTransaction.SourceAmount == transaction.SourceAmount &&
|
||||
|
||||
+10
-10
@@ -12,13 +12,13 @@ import (
|
||||
)
|
||||
|
||||
type UsersApi struct {
|
||||
users *services.UserService
|
||||
users *services.UserService
|
||||
tokens *services.TokenService
|
||||
}
|
||||
|
||||
var (
|
||||
Users = &UsersApi{
|
||||
users: services.Users,
|
||||
users: services.Users,
|
||||
tokens: services.Tokens,
|
||||
}
|
||||
)
|
||||
@@ -37,10 +37,10 @@ func (a *UsersApi) UserRegisterHandler(c *core.Context) (interface{}, *errs.Erro
|
||||
userRegisterReq.Nickname = strings.TrimSpace(userRegisterReq.Nickname)
|
||||
|
||||
user := &models.User{
|
||||
Username: userRegisterReq.Username,
|
||||
Email: userRegisterReq.Email,
|
||||
Nickname: userRegisterReq.Nickname,
|
||||
Password: userRegisterReq.Password,
|
||||
Username: userRegisterReq.Username,
|
||||
Email: userRegisterReq.Email,
|
||||
Nickname: userRegisterReq.Nickname,
|
||||
Password: userRegisterReq.Password,
|
||||
DefaultCurrency: userRegisterReq.DefaultCurrency,
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ func (a *UsersApi) UserRegisterHandler(c *core.Context) (interface{}, *errs.Erro
|
||||
|
||||
authResp := &models.AuthResponse{
|
||||
Need2FA: false,
|
||||
User: user.ToUserBasicInfo(),
|
||||
User: user.ToUserBasicInfo(),
|
||||
}
|
||||
|
||||
token, claims, err := a.tokens.CreateToken(user, c)
|
||||
@@ -114,8 +114,8 @@ func (a *UsersApi) UserUpdateProfileHandler(c *core.Context) (interface{}, *errs
|
||||
|
||||
anythingUpdate := false
|
||||
userNew := &models.User{
|
||||
Uid: user.Uid,
|
||||
Salt: user.Salt,
|
||||
Uid: user.Uid,
|
||||
Salt: user.Salt,
|
||||
Rands: user.Rands,
|
||||
}
|
||||
|
||||
@@ -161,7 +161,7 @@ func (a *UsersApi) UserUpdateProfileHandler(c *core.Context) (interface{}, *errs
|
||||
|
||||
log.InfofWithRequestId(c, "[users.UserUpdateProfileHandler] user \"uid:%d\" has updated successfully", user.Uid)
|
||||
|
||||
resp := &models.UserProfileUpdateResponse {
|
||||
resp := &models.UserProfileUpdateResponse{
|
||||
User: user.ToUserBasicInfo(),
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ func (s *DataStore) DoTransaction(key int64, fn func(sess *xorm.Session) error)
|
||||
return s.Choose(key).DoTransaction(fn)
|
||||
}
|
||||
|
||||
func (s *DataStore) SyncStructs(beans... interface{}) error {
|
||||
func (s *DataStore) SyncStructs(beans ...interface{}) error {
|
||||
var err error
|
||||
|
||||
for i := 0; i < len(s.databases); i++ {
|
||||
@@ -36,7 +36,7 @@ func (s *DataStore) SyncStructs(beans... interface{}) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func NewDataStore(databases... *Database) (*DataStore, error) {
|
||||
func NewDataStore(databases ...*Database) (*DataStore, error) {
|
||||
if len(databases) < 1 {
|
||||
return nil, errs.ErrDatabaseIsNull
|
||||
}
|
||||
|
||||
@@ -17,8 +17,8 @@ import (
|
||||
)
|
||||
|
||||
type DataStoreContainer struct {
|
||||
UserStore *DataStore
|
||||
TokenStore *DataStore
|
||||
UserStore *DataStore
|
||||
TokenStore *DataStore
|
||||
UserDataStore *DataStore
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
)
|
||||
|
||||
type XOrmLoggerAdapter struct {
|
||||
enable bool
|
||||
enable bool
|
||||
logLevel settings.Level
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ func (logger XOrmLoggerAdapter) IsShowSQL() bool {
|
||||
|
||||
func NewXOrmLoggerAdapter(showSql bool, logLevel settings.Level) xorm.Logger {
|
||||
return XOrmLoggerAdapter{
|
||||
enable: showSql,
|
||||
enable: showSql,
|
||||
logLevel: logLevel,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
)
|
||||
|
||||
type LogFormatter struct {
|
||||
Prefix string
|
||||
Prefix string
|
||||
DisableLevel bool
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
const REQUEST_ID_HEADER = "X-Request-ID"
|
||||
|
||||
func RequestId(config *settings.Config) core.MiddlewareHandlerFunc {
|
||||
return func (c *core.Context) {
|
||||
return func(c *core.Context) {
|
||||
if requestid.Container.Current == nil {
|
||||
c.Next()
|
||||
return
|
||||
|
||||
@@ -19,8 +19,8 @@ type TransactionTagCreateRequest struct {
|
||||
}
|
||||
|
||||
type TransactionTagModifyRequest struct {
|
||||
Id int64 `json:"id,string" binding:"required,min=1"`
|
||||
Name string `json:"name" binding:"required,notBlank,max=32"`
|
||||
Id int64 `json:"id,string" binding:"required,min=1"`
|
||||
Name string `json:"name" binding:"required,notBlank,max=32"`
|
||||
}
|
||||
|
||||
type TransactionTagHideRequest struct {
|
||||
|
||||
+11
-11
@@ -63,7 +63,7 @@ func (s *TokenService) ParseToken(c *core.Context) (*jwt.Token, *core.UserTokenC
|
||||
claims := &core.UserTokenClaims{}
|
||||
|
||||
token, err := request.ParseFromRequest(c.Request, request.AuthorizationHeaderExtractor,
|
||||
func (token *jwt.Token) (interface{}, error) {
|
||||
func(token *jwt.Token) (interface{}, error) {
|
||||
uid, err := utils.StringToInt64(claims.Id)
|
||||
now := time.Now().Unix()
|
||||
|
||||
@@ -205,8 +205,8 @@ func (s *TokenService) ParseFromTokenId(tokenId string) (*models.TokenRecord, er
|
||||
}
|
||||
|
||||
tokenRecord := &models.TokenRecord{
|
||||
Uid: uid,
|
||||
UserTokenId: userTokenId,
|
||||
Uid: uid,
|
||||
UserTokenId: userTokenId,
|
||||
CreatedUnixTime: createdUnixTime,
|
||||
}
|
||||
|
||||
@@ -222,10 +222,10 @@ func (s *TokenService) createToken(user *models.User, tokenType core.TokenType,
|
||||
now := time.Now()
|
||||
|
||||
tokenRecord := &models.TokenRecord{
|
||||
Uid: user.Uid,
|
||||
UserTokenId: s.getUserTokenId(),
|
||||
TokenType: tokenType,
|
||||
UserAgent: userAgent,
|
||||
Uid: user.Uid,
|
||||
UserTokenId: s.getUserTokenId(),
|
||||
TokenType: tokenType,
|
||||
UserAgent: userAgent,
|
||||
CreatedUnixTime: now.Unix(),
|
||||
ExpiredUnixTime: now.Add(expiryDate).Unix(),
|
||||
}
|
||||
@@ -236,11 +236,11 @@ func (s *TokenService) createToken(user *models.User, tokenType core.TokenType,
|
||||
|
||||
claims := &core.UserTokenClaims{
|
||||
UserTokenId: utils.Int64ToString(tokenRecord.UserTokenId),
|
||||
Username: user.Username,
|
||||
Type: tokenRecord.TokenType,
|
||||
Username: user.Username,
|
||||
Type: tokenRecord.TokenType,
|
||||
StandardClaims: jwt.StandardClaims{
|
||||
Id: utils.Int64ToString(tokenRecord.Uid),
|
||||
IssuedAt: tokenRecord.CreatedUnixTime,
|
||||
Id: utils.Int64ToString(tokenRecord.Uid),
|
||||
IssuedAt: tokenRecord.CreatedUnixTime,
|
||||
ExpiresAt: tokenRecord.ExpiredUnixTime,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -214,7 +214,7 @@ func (s *TransactionCategoryService) HideCategory(uid int64, ids []int64, hidden
|
||||
now := time.Now().Unix()
|
||||
|
||||
updateModel := &models.TransactionCategory{
|
||||
Hidden: hidden,
|
||||
Hidden: hidden,
|
||||
UpdatedUnixTime: now,
|
||||
}
|
||||
|
||||
@@ -264,7 +264,7 @@ func (s *TransactionCategoryService) DeleteCategory(uid int64, categoryId int64)
|
||||
now := time.Now().Unix()
|
||||
|
||||
updateModel := &models.TransactionCategory{
|
||||
Deleted: true,
|
||||
Deleted: true,
|
||||
DeletedUnixTime: now,
|
||||
}
|
||||
|
||||
|
||||
@@ -164,7 +164,7 @@ func (s *TransactionTagService) HideTag(uid int64, ids []int64, hidden bool) err
|
||||
now := time.Now().Unix()
|
||||
|
||||
updateModel := &models.TransactionTag{
|
||||
Hidden: hidden,
|
||||
Hidden: hidden,
|
||||
UpdatedUnixTime: now,
|
||||
}
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ func (s *TransactionService) GetTransactionsInMonthByPage(uid int64, year int, m
|
||||
endUnixTime := endTime.Unix()
|
||||
|
||||
var transactions []*models.Transaction
|
||||
err = s.UserDataDB(uid).Where("uid=? AND deleted=? AND transaction_time>=? AND transaction_time<?", uid, false, startUnixTime, endUnixTime).Limit(count, count * (page - 1)).OrderBy("transaction_time desc").Find(&transactions)
|
||||
err = s.UserDataDB(uid).Where("uid=? AND deleted=? AND transaction_time>=? AND transaction_time<?", uid, false, startUnixTime, endUnixTime).Limit(count, count*(page-1)).OrderBy("transaction_time desc").Find(&transactions)
|
||||
|
||||
return transactions, err
|
||||
}
|
||||
@@ -268,7 +268,7 @@ func (s *TransactionService) CreateTransaction(transaction *models.Transaction,
|
||||
return err
|
||||
} else if !has {
|
||||
return errs.ErrDatabaseOperationFailed
|
||||
} else if sameSecondLatestTransaction.TransactionTime == maxTransactionTime - 1 {
|
||||
} else if sameSecondLatestTransaction.TransactionTime == maxTransactionTime-1 {
|
||||
return errs.ErrTooMuchTransactionInOneSecond
|
||||
}
|
||||
|
||||
@@ -465,9 +465,9 @@ func (s *TransactionService) ModifyTransaction(transaction *models.Transaction,
|
||||
|
||||
has, err = sess.Where("uid=? AND deleted=? AND transaction_time>=? AND transaction_time<=?", transaction.Uid, false, minTransactionTime, maxTransactionTime).OrderBy("transaction_time desc").Limit(1).Get(sameSecondLatestTransaction)
|
||||
|
||||
if has && sameSecondLatestTransaction.TransactionTime < maxTransactionTime - 1 {
|
||||
if has && sameSecondLatestTransaction.TransactionTime < maxTransactionTime-1 {
|
||||
transaction.TransactionTime = sameSecondLatestTransaction.TransactionTime + 1
|
||||
} else if has && sameSecondLatestTransaction.TransactionTime == maxTransactionTime - 1 {
|
||||
} else if has && sameSecondLatestTransaction.TransactionTime == maxTransactionTime-1 {
|
||||
return errs.ErrTooMuchTransactionInOneSecond
|
||||
}
|
||||
|
||||
@@ -634,7 +634,7 @@ func (s *TransactionService) DeleteTransaction(uid int64, transactionId int64) e
|
||||
now := time.Now().Unix()
|
||||
|
||||
updateModel := &models.Transaction{
|
||||
Deleted: true,
|
||||
Deleted: true,
|
||||
DeletedUnixTime: now,
|
||||
}
|
||||
|
||||
|
||||
@@ -3,9 +3,9 @@ package services
|
||||
import (
|
||||
"time"
|
||||
|
||||
"xorm.io/xorm"
|
||||
"github.com/pquerna/otp"
|
||||
"github.com/pquerna/otp/totp"
|
||||
"xorm.io/xorm"
|
||||
|
||||
"github.com/mayswind/lab/pkg/datastore"
|
||||
"github.com/mayswind/lab/pkg/errs"
|
||||
|
||||
@@ -10,7 +10,7 @@ func StringToInt32(str string) (int, error) {
|
||||
return strconv.Atoi(str)
|
||||
}
|
||||
|
||||
func StringTryToInt32(str string, defaultValue int) int {
|
||||
func StringTryToInt32(str string, defaultValue int) int {
|
||||
num, err := StringToInt32(str)
|
||||
|
||||
if err != nil {
|
||||
|
||||
@@ -17,7 +17,7 @@ func GetMinTransactionTimeFromUnixTime(unixTime int64) int64 {
|
||||
}
|
||||
|
||||
func GetMaxTransactionTimeFromUnixTime(unixTime int64) int64 {
|
||||
return unixTime * 1000 + 999
|
||||
return unixTime*1000 + 999
|
||||
}
|
||||
|
||||
func GetUnixTimeFromTransactionTime(transactionTime int64) int64 {
|
||||
|
||||
@@ -3,8 +3,8 @@ package utils
|
||||
import "regexp"
|
||||
|
||||
var (
|
||||
UsernamePattern = regexp.MustCompile("^(?i)[a-z0-9_-]+$")
|
||||
EmailPattern = regexp.MustCompile("^(?i)(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])$")
|
||||
UsernamePattern = regexp.MustCompile("^(?i)[a-z0-9_-]+$")
|
||||
EmailPattern = regexp.MustCompile("^(?i)(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])$")
|
||||
HexRGBColorPattern = regexp.MustCompile("^(?i)([0-9a-f]{6}|[0-9a-f]{3})$")
|
||||
)
|
||||
|
||||
|
||||
@@ -148,7 +148,7 @@ func AESGCMDecrypt(key []byte, ciphertext []byte) ([]byte, error) {
|
||||
|
||||
nonceSize := aesgcm.NonceSize()
|
||||
|
||||
if len(ciphertext) - nonceSize <= 0 {
|
||||
if len(ciphertext)-nonceSize <= 0 {
|
||||
return nil, errs.ErrCiphertextInvalid
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
const PARENT_ACCOUNT_CURRENCY_PLACEHODLER = "---"
|
||||
|
||||
// ISO 4217
|
||||
var ALL_CURRENCY_NAMES = map[string]bool {
|
||||
var ALL_CURRENCY_NAMES = map[string]bool{
|
||||
"AED": true, //UAE Dirham
|
||||
"AFN": true, //Afghani
|
||||
"ALL": true, //Lek
|
||||
|
||||
Reference in New Issue
Block a user