diff --git a/pkg/controllers/transactions.go b/pkg/controllers/transactions.go index 122b1ae..3721c98 100644 --- a/pkg/controllers/transactions.go +++ b/pkg/controllers/transactions.go @@ -34,10 +34,14 @@ func (wc *TransactionController) New(c *gin.Context) { } func (wc *TransactionController) GetAll(c *gin.Context) { + body := new(models.Auth) + auth := c.MustGet("auth") + body.Id = auth.(*models.Auth).Id + fr := FilteredResponse(c) wallet, _ := c.GetQuery("walletId") - wc.TransactionService.GetAll(wallet, fr) + wc.TransactionService.GetAll(body, wallet, fr) c.JSON(200, fr) } diff --git a/pkg/services/transactions.go b/pkg/services/transactions.go index e70a924..09708bd 100644 --- a/pkg/services/transactions.go +++ b/pkg/services/transactions.go @@ -32,10 +32,10 @@ func (as *TransactionService) New(body *models.NewTransactionBody) *models.Trans return tm } -func (as *TransactionService) GetAll(walletId string, filtered *models.FilteredResponse) { +func (as *TransactionService) GetAll(am *models.Auth, walletId string, filtered *models.FilteredResponse) { wm := new([]models.Transaction) - query := as.Db.Model((wm)) + query := as.Db.Model((wm)).Relation("Wallet").Where("wallet.? = ?", pg.Ident("user_id"), am.Id) if walletId != "" { query = query.Where("? = ?", pg.Ident("wallet_id"), walletId) }