upgraded migrations and context usage

This commit is contained in:
Fran Jurmanović
2021-07-03 00:01:25 +02:00
parent 4189a0d333
commit 788ff3a146
33 changed files with 321 additions and 251 deletions

View File

@@ -1,6 +1,7 @@
package services
import (
"context"
"wallet-api/pkg/models"
"wallet-api/pkg/utl/common"
@@ -11,22 +12,26 @@ type SubscriptionTypeService struct {
Db *pg.DB
}
func (as *SubscriptionTypeService) New(body *models.NewSubscriptionTypeBody) *models.SubscriptionType {
func (as *SubscriptionTypeService) New(ctx context.Context, body *models.NewSubscriptionTypeBody) *models.SubscriptionType {
db := as.Db.WithContext(ctx)
tm := new(models.SubscriptionType)
tm.Init()
tm.Name = body.Name
tm.Type = body.Type
as.Db.Model(tm).Insert()
db.Model(tm).Insert()
return tm
}
func (as *SubscriptionTypeService) GetAll(embed string) *[]models.SubscriptionType {
func (as *SubscriptionTypeService) GetAll(ctx context.Context, embed string) *[]models.SubscriptionType {
db := as.Db.WithContext(ctx)
wm := new([]models.SubscriptionType)
query := as.Db.Model(wm)
query := db.Model(wm)
common.GenerateEmbed(query, embed).Select()
return wm