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"
|
||||
"wallet-api/pkg/models"
|
||||
"wallet-api/pkg/utl/common"
|
||||
|
||||
@@ -11,22 +12,26 @@ type TransactionTypeService struct {
|
||||
Db *pg.DB
|
||||
}
|
||||
|
||||
func (as *TransactionTypeService) New(body *models.NewTransactionTypeBody) *models.TransactionType {
|
||||
func (as *TransactionTypeService) New(ctx context.Context, body *models.NewTransactionTypeBody) *models.TransactionType {
|
||||
db := as.Db.WithContext(ctx)
|
||||
|
||||
tm := new(models.TransactionType)
|
||||
|
||||
tm.Init()
|
||||
tm.Name = body.Name
|
||||
tm.Type = body.Type
|
||||
|
||||
as.Db.Model(tm).Insert()
|
||||
db.Model(tm).Insert()
|
||||
|
||||
return tm
|
||||
}
|
||||
|
||||
func (as *TransactionTypeService) GetAll(embed string) *[]models.TransactionType {
|
||||
func (as *TransactionTypeService) GetAll(ctx context.Context, embed string) *[]models.TransactionType {
|
||||
db := as.Db.WithContext(ctx)
|
||||
|
||||
wm := new([]models.TransactionType)
|
||||
|
||||
query := as.Db.Model(wm)
|
||||
query := db.Model(wm)
|
||||
common.GenerateEmbed(query, embed).Select()
|
||||
|
||||
return wm
|
||||
|
||||
Reference in New Issue
Block a user