mirror of
https://github.com/FJurmanovic/wallet-go-api.git
synced 2026-02-06 06:08:16 +00:00
WA-10 - Implemented transactions
This commit is contained in:
33
pkg/services/transactionTypes.go
Normal file
33
pkg/services/transactionTypes.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"wallet-api/pkg/models"
|
||||
"wallet-api/pkg/utl/common"
|
||||
|
||||
"github.com/go-pg/pg/v10"
|
||||
)
|
||||
|
||||
type TransactionTypeService struct {
|
||||
Db *pg.DB
|
||||
}
|
||||
|
||||
func (as *TransactionTypeService) New(body *models.NewTransactionTypeBody) *models.TransactionType {
|
||||
tm := new(models.TransactionType)
|
||||
|
||||
tm.Init()
|
||||
tm.Name = body.Name
|
||||
tm.Type = body.Type
|
||||
|
||||
as.Db.Model(tm).Insert()
|
||||
|
||||
return tm
|
||||
}
|
||||
|
||||
func (as *TransactionTypeService) GetAll(embed string) *[]models.TransactionType {
|
||||
wm := new([]models.TransactionType)
|
||||
|
||||
query := as.Db.Model(wm)
|
||||
common.GenerateEmbed(query, embed).Select()
|
||||
|
||||
return wm
|
||||
}
|
||||
35
pkg/services/transactions.go
Normal file
35
pkg/services/transactions.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"wallet-api/pkg/models"
|
||||
"wallet-api/pkg/utl/common"
|
||||
|
||||
"github.com/go-pg/pg/v10"
|
||||
)
|
||||
|
||||
type TransactionService struct {
|
||||
Db *pg.DB
|
||||
}
|
||||
|
||||
func (as *TransactionService) New(body *models.NewTransactionBody) *models.Transaction {
|
||||
tm := new(models.Transaction)
|
||||
|
||||
tm.Init()
|
||||
tm.WalletID = body.WalletID
|
||||
tm.TransactionTypeID = body.TransactionTypeID
|
||||
tm.Description = body.Description
|
||||
tm.TransactionDate = body.TransactionDate
|
||||
|
||||
as.Db.Model(tm).Insert()
|
||||
|
||||
return tm
|
||||
}
|
||||
|
||||
func (as *TransactionService) GetAll(walletId string, embed string) *[]models.Transaction {
|
||||
wm := new([]models.Transaction)
|
||||
|
||||
query := as.Db.Model(wm).Where("? = ?", pg.Ident("wallet_id"), walletId)
|
||||
common.GenerateEmbed(query, embed).Select()
|
||||
|
||||
return wm
|
||||
}
|
||||
Reference in New Issue
Block a user