mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-20 01:34:24 +08:00
format code
This commit is contained in:
@@ -187,9 +187,9 @@ func (a *AuthorizationsApi) TwoFactorAuthorizeByRecoveryCodeHandler(c *core.Cont
|
|||||||
return authResp, nil
|
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{
|
return &models.AuthResponse{
|
||||||
Token : token,
|
Token: token,
|
||||||
Need2FA: need2FA,
|
Need2FA: need2FA,
|
||||||
User: user.ToUserBasicInfo(),
|
User: user.ToUserBasicInfo(),
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -5,7 +5,7 @@ import (
|
|||||||
"github.com/mayswind/lab/pkg/errs"
|
"github.com/mayswind/lab/pkg/errs"
|
||||||
)
|
)
|
||||||
|
|
||||||
type DefaultApi struct {}
|
type DefaultApi struct{}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
Default = &DefaultApi{}
|
Default = &DefaultApi{}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import (
|
|||||||
|
|
||||||
const EuroCentralBankExchangeRateUrl = "https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml"
|
const EuroCentralBankExchangeRateUrl = "https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml"
|
||||||
|
|
||||||
type ExchangeRatesApi struct {}
|
type ExchangeRatesApi struct{}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ExchangeRates = &ExchangeRatesApi{}
|
ExchangeRates = &ExchangeRatesApi{}
|
||||||
|
|||||||
@@ -171,7 +171,7 @@ func (a *TransactionCategoriesApi) CategoryCreateBatchHandler(c *core.Context) (
|
|||||||
}
|
}
|
||||||
|
|
||||||
categoriesMap[nil][i] = category
|
categoriesMap[nil][i] = category
|
||||||
categoryTypeMaxOrderMap[categoryCreateReq.Type] = maxOrderId+1
|
categoryTypeMaxOrderMap[categoryCreateReq.Type] = maxOrderId + 1
|
||||||
totalCount++
|
totalCount++
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ func (a *TransactionsApi) TransactionListHandler(c *core.Context) (interface{},
|
|||||||
}
|
}
|
||||||
|
|
||||||
uid := c.GetCurrentUid()
|
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 {
|
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())
|
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 &&
|
if newTransaction.CategoryId == transaction.CategoryId &&
|
||||||
newTransaction.TransactionTime / 1000 == transaction.TransactionTime / 1000 &&
|
newTransaction.TransactionTime/1000 == transaction.TransactionTime/1000 &&
|
||||||
newTransaction.SourceAccountId == transaction.SourceAccountId &&
|
newTransaction.SourceAccountId == transaction.SourceAccountId &&
|
||||||
newTransaction.DestinationAccountId == transaction.DestinationAccountId &&
|
newTransaction.DestinationAccountId == transaction.DestinationAccountId &&
|
||||||
newTransaction.SourceAmount == transaction.SourceAmount &&
|
newTransaction.SourceAmount == transaction.SourceAmount &&
|
||||||
|
|||||||
+1
-1
@@ -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)
|
log.InfofWithRequestId(c, "[users.UserUpdateProfileHandler] user \"uid:%d\" has updated successfully", user.Uid)
|
||||||
|
|
||||||
resp := &models.UserProfileUpdateResponse {
|
resp := &models.UserProfileUpdateResponse{
|
||||||
User: user.ToUserBasicInfo(),
|
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)
|
return s.Choose(key).DoTransaction(fn)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DataStore) SyncStructs(beans... interface{}) error {
|
func (s *DataStore) SyncStructs(beans ...interface{}) error {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
for i := 0; i < len(s.databases); i++ {
|
for i := 0; i < len(s.databases); i++ {
|
||||||
@@ -36,7 +36,7 @@ func (s *DataStore) SyncStructs(beans... interface{}) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDataStore(databases... *Database) (*DataStore, error) {
|
func NewDataStore(databases ...*Database) (*DataStore, error) {
|
||||||
if len(databases) < 1 {
|
if len(databases) < 1 {
|
||||||
return nil, errs.ErrDatabaseIsNull
|
return nil, errs.ErrDatabaseIsNull
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import (
|
|||||||
const REQUEST_ID_HEADER = "X-Request-ID"
|
const REQUEST_ID_HEADER = "X-Request-ID"
|
||||||
|
|
||||||
func RequestId(config *settings.Config) core.MiddlewareHandlerFunc {
|
func RequestId(config *settings.Config) core.MiddlewareHandlerFunc {
|
||||||
return func (c *core.Context) {
|
return func(c *core.Context) {
|
||||||
if requestid.Container.Current == nil {
|
if requestid.Container.Current == nil {
|
||||||
c.Next()
|
c.Next()
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ func (s *TokenService) ParseToken(c *core.Context) (*jwt.Token, *core.UserTokenC
|
|||||||
claims := &core.UserTokenClaims{}
|
claims := &core.UserTokenClaims{}
|
||||||
|
|
||||||
token, err := request.ParseFromRequest(c.Request, request.AuthorizationHeaderExtractor,
|
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)
|
uid, err := utils.StringToInt64(claims.Id)
|
||||||
now := time.Now().Unix()
|
now := time.Now().Unix()
|
||||||
|
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ func (s *TransactionService) GetTransactionsInMonthByPage(uid int64, year int, m
|
|||||||
endUnixTime := endTime.Unix()
|
endUnixTime := endTime.Unix()
|
||||||
|
|
||||||
var transactions []*models.Transaction
|
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
|
return transactions, err
|
||||||
}
|
}
|
||||||
@@ -268,7 +268,7 @@ func (s *TransactionService) CreateTransaction(transaction *models.Transaction,
|
|||||||
return err
|
return err
|
||||||
} else if !has {
|
} else if !has {
|
||||||
return errs.ErrDatabaseOperationFailed
|
return errs.ErrDatabaseOperationFailed
|
||||||
} else if sameSecondLatestTransaction.TransactionTime == maxTransactionTime - 1 {
|
} else if sameSecondLatestTransaction.TransactionTime == maxTransactionTime-1 {
|
||||||
return errs.ErrTooMuchTransactionInOneSecond
|
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)
|
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
|
transaction.TransactionTime = sameSecondLatestTransaction.TransactionTime + 1
|
||||||
} else if has && sameSecondLatestTransaction.TransactionTime == maxTransactionTime - 1 {
|
} else if has && sameSecondLatestTransaction.TransactionTime == maxTransactionTime-1 {
|
||||||
return errs.ErrTooMuchTransactionInOneSecond
|
return errs.ErrTooMuchTransactionInOneSecond
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,9 +3,9 @@ package services
|
|||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"xorm.io/xorm"
|
|
||||||
"github.com/pquerna/otp"
|
"github.com/pquerna/otp"
|
||||||
"github.com/pquerna/otp/totp"
|
"github.com/pquerna/otp/totp"
|
||||||
|
"xorm.io/xorm"
|
||||||
|
|
||||||
"github.com/mayswind/lab/pkg/datastore"
|
"github.com/mayswind/lab/pkg/datastore"
|
||||||
"github.com/mayswind/lab/pkg/errs"
|
"github.com/mayswind/lab/pkg/errs"
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ func GetMinTransactionTimeFromUnixTime(unixTime int64) int64 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func GetMaxTransactionTimeFromUnixTime(unixTime int64) int64 {
|
func GetMaxTransactionTimeFromUnixTime(unixTime int64) int64 {
|
||||||
return unixTime * 1000 + 999
|
return unixTime*1000 + 999
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetUnixTimeFromTransactionTime(transactionTime int64) int64 {
|
func GetUnixTimeFromTransactionTime(transactionTime int64) int64 {
|
||||||
|
|||||||
@@ -148,7 +148,7 @@ func AESGCMDecrypt(key []byte, ciphertext []byte) ([]byte, error) {
|
|||||||
|
|
||||||
nonceSize := aesgcm.NonceSize()
|
nonceSize := aesgcm.NonceSize()
|
||||||
|
|
||||||
if len(ciphertext) - nonceSize <= 0 {
|
if len(ciphertext)-nonceSize <= 0 {
|
||||||
return nil, errs.ErrCiphertextInvalid
|
return nil, errs.ErrCiphertextInvalid
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import (
|
|||||||
const PARENT_ACCOUNT_CURRENCY_PLACEHODLER = "---"
|
const PARENT_ACCOUNT_CURRENCY_PLACEHODLER = "---"
|
||||||
|
|
||||||
// ISO 4217
|
// ISO 4217
|
||||||
var ALL_CURRENCY_NAMES = map[string]bool {
|
var ALL_CURRENCY_NAMES = map[string]bool{
|
||||||
"AED": true, //UAE Dirham
|
"AED": true, //UAE Dirham
|
||||||
"AFN": true, //Afghani
|
"AFN": true, //Afghani
|
||||||
"ALL": true, //Lek
|
"ALL": true, //Lek
|
||||||
|
|||||||
Reference in New Issue
Block a user