upgraded migrations and context usage

This commit is contained in:
Fran Jurmanović
2021-07-03 00:01:25 +02:00
parent 4189a0d333
commit 788ff3a146
33 changed files with 321 additions and 251 deletions

View File

@@ -1,6 +1,7 @@
package services
import (
"context"
"math"
"time"
"wallet-api/pkg/models"
@@ -13,7 +14,9 @@ type TransactionService struct {
Ss *SubscriptionService
}
func (as *TransactionService) New(body *models.NewTransactionBody) *models.Transaction {
func (as *TransactionService) New(ctx context.Context, body *models.NewTransactionBody) *models.Transaction {
db := as.Db.WithContext(ctx)
tm := new(models.Transaction)
amount, _ := body.Amount.Float64()
@@ -29,16 +32,18 @@ func (as *TransactionService) New(body *models.NewTransactionBody) *models.Trans
tm.TransactionDate = time.Now()
}
as.Db.Model(tm).Insert()
db.Model(tm).Insert()
return tm
}
func (as *TransactionService) GetAll(am *models.Auth, walletId string, filtered *models.FilteredResponse) {
func (as *TransactionService) GetAll(ctx context.Context, am *models.Auth, walletId string, filtered *models.FilteredResponse) {
db := as.Db.WithContext(ctx)
wm := new([]models.Transaction)
sm := new([]models.Subscription)
tx, _ := as.Db.Begin()
tx, _ := db.Begin()
defer tx.Rollback()
query2 := tx.Model(sm).Relation("Wallet").Where("wallet.? = ?", pg.Ident("user_id"), am.Id)