feat(transaction-recurring): #100 fix database lock bug #137
@@ -200,7 +200,7 @@ func (h TransactionImpl) handleUpdateTransaction() http.HandlerFunc {
|
||||
|
||||
var transaction *types.Transaction
|
||||
if idStr == "new" {
|
||||
transaction, err = h.s.Add(user, input)
|
||||
transaction, err = h.s.Add(nil, user, input)
|
||||
if err != nil {
|
||||
handleError(w, r, err)
|
||||
return
|
||||
|
||||
@@ -25,7 +25,7 @@ var (
|
||||
)
|
||||
|
||||
type Transaction interface {
|
||||
Add(user *types.User, transaction types.Transaction) (*types.Transaction, error)
|
||||
Add(tx *sqlx.Tx, user *types.User, transaction types.Transaction) (*types.Transaction, error)
|
||||
Update(user *types.User, transaction types.Transaction) (*types.Transaction, error)
|
||||
Get(user *types.User, id string) (*types.Transaction, error)
|
||||
GetAll(user *types.User, filter types.TransactionItemsFilter) ([]*types.Transaction, error)
|
||||
@@ -48,14 +48,16 @@ func NewTransaction(db *sqlx.DB, random Random, clock Clock) Transaction {
|
||||
}
|
||||
}
|
||||
|
||||
func (s TransactionImpl) Add(user *types.User, transactionInput types.Transaction) (*types.Transaction, error) {
|
||||
func (s TransactionImpl) Add(tx *sqlx.Tx, user *types.User, transactionInput types.Transaction) (*types.Transaction, error) {
|
||||
transactionMetric.WithLabelValues("add").Inc()
|
||||
|
||||
if user == nil {
|
||||
return nil, ErrUnauthorized
|
||||
}
|
||||
|
||||
tx, err := s.db.Beginx()
|
||||
var err error
|
||||
if tx == nil {
|
||||
tx, err = s.db.Beginx()
|
||||
err = db.TransformAndLogDbError("transaction Add", nil, err)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -63,6 +65,7 @@ func (s TransactionImpl) Add(user *types.User, transactionInput types.Transactio
|
||||
defer func() {
|
||||
_ = tx.Rollback()
|
||||
}()
|
||||
}
|
||||
|
||||
transaction, err := s.validateAndEnrichTransaction(tx, nil, user.Id, transactionInput)
|
||||
if err != nil {
|
||||
|
||||
@@ -364,7 +364,7 @@ func (s TransactionRecurringImpl) GenerateTransactions(user *types.User) error {
|
||||
Value: transactionRecurring.Value,
|
||||
}
|
||||
|
||||
_, err = s.transaction.Add(user, transaction)
|
||||
_, err = s.transaction.Add(tx, user, transaction)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user