mirror of
https://github.com/FJurmanovic/wallet-go-api.git
synced 2026-02-06 06:08:16 +00:00
upgraded migrations and context usage
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user