mirror of
https://github.com/FJurmanovic/wallet-go-api.git
synced 2026-02-06 06:08:16 +00:00
Added filtered GET request
This commit is contained in:
18
pkg/services/services.go
Normal file
18
pkg/services/services.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"wallet-api/pkg/models"
|
||||
"wallet-api/pkg/utl/common"
|
||||
|
||||
"github.com/go-pg/pg/v10"
|
||||
)
|
||||
|
||||
func FilteredResponse(qry *pg.Query, mdl interface{}, filtered *models.FilteredResponse) {
|
||||
qry = qry.Limit(filtered.Rpp).Offset((filtered.Page - 1) * filtered.Rpp)
|
||||
common.GenerateEmbed(qry, filtered.Embed)
|
||||
count, err := qry.SelectAndCount()
|
||||
common.CheckError(err)
|
||||
|
||||
filtered.TotalRecords = count
|
||||
filtered.Items = mdl
|
||||
}
|
||||
@@ -2,7 +2,6 @@ package services
|
||||
|
||||
import (
|
||||
"wallet-api/pkg/models"
|
||||
"wallet-api/pkg/utl/common"
|
||||
|
||||
"github.com/go-pg/pg/v10"
|
||||
)
|
||||
@@ -25,11 +24,9 @@ func (as *TransactionService) New(body *models.NewTransactionBody) *models.Trans
|
||||
return tm
|
||||
}
|
||||
|
||||
func (as *TransactionService) GetAll(walletId string, embed string) *[]models.Transaction {
|
||||
func (as *TransactionService) GetAll(walletId string, filtered *models.FilteredResponse) {
|
||||
wm := new([]models.Transaction)
|
||||
|
||||
query := as.Db.Model(wm).Where("? = ?", pg.Ident("wallet_id"), walletId)
|
||||
common.GenerateEmbed(query, embed).Select()
|
||||
|
||||
return wm
|
||||
FilteredResponse(query, wm, filtered)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user