Rework phone subscription at the database layer so that we have a seprate phone status and subscriptions to district communications.
563 lines
18 KiB
Go
563 lines
18 KiB
Go
// Code generated by BobGen psql v0.42.5. DO NOT EDIT.
|
|
// This file is meant to be re-generated in place and/or deleted at any time.
|
|
|
|
package factory
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/Gleipnir-Technology/bob"
|
|
models "github.com/Gleipnir-Technology/nidus-sync/db/models"
|
|
"github.com/aarondl/opt/omit"
|
|
"github.com/jaswdr/faker/v2"
|
|
)
|
|
|
|
type CommsEmailContactMod interface {
|
|
Apply(context.Context, *CommsEmailContactTemplate)
|
|
}
|
|
|
|
type CommsEmailContactModFunc func(context.Context, *CommsEmailContactTemplate)
|
|
|
|
func (f CommsEmailContactModFunc) Apply(ctx context.Context, n *CommsEmailContactTemplate) {
|
|
f(ctx, n)
|
|
}
|
|
|
|
type CommsEmailContactModSlice []CommsEmailContactMod
|
|
|
|
func (mods CommsEmailContactModSlice) Apply(ctx context.Context, n *CommsEmailContactTemplate) {
|
|
for _, f := range mods {
|
|
f.Apply(ctx, n)
|
|
}
|
|
}
|
|
|
|
// CommsEmailContactTemplate is an object representing the database table.
|
|
// all columns are optional and should be set by mods
|
|
type CommsEmailContactTemplate struct {
|
|
Address func() string
|
|
Confirmed func() bool
|
|
IsSubscribed func() bool
|
|
PublicID func() string
|
|
|
|
r commsEmailContactR
|
|
f *Factory
|
|
|
|
alreadyPersisted bool
|
|
}
|
|
|
|
type commsEmailContactR struct {
|
|
DestinationEmailLogs []*commsEmailContactRDestinationEmailLogsR
|
|
Organizations []*commsEmailContactROrganizationsR
|
|
}
|
|
|
|
type commsEmailContactRDestinationEmailLogsR struct {
|
|
number int
|
|
o *CommsEmailLogTemplate
|
|
}
|
|
type commsEmailContactROrganizationsR struct {
|
|
number int
|
|
o *OrganizationTemplate
|
|
}
|
|
|
|
// Apply mods to the CommsEmailContactTemplate
|
|
func (o *CommsEmailContactTemplate) Apply(ctx context.Context, mods ...CommsEmailContactMod) {
|
|
for _, mod := range mods {
|
|
mod.Apply(ctx, o)
|
|
}
|
|
}
|
|
|
|
// setModelRels creates and sets the relationships on *models.CommsEmailContact
|
|
// according to the relationships in the template. Nothing is inserted into the db
|
|
func (t CommsEmailContactTemplate) setModelRels(o *models.CommsEmailContact) {
|
|
if t.r.DestinationEmailLogs != nil {
|
|
rel := models.CommsEmailLogSlice{}
|
|
for _, r := range t.r.DestinationEmailLogs {
|
|
related := r.o.BuildMany(r.number)
|
|
for _, rel := range related {
|
|
rel.Destination = o.Address // h2
|
|
rel.R.DestinationEmailContact = o
|
|
}
|
|
rel = append(rel, related...)
|
|
}
|
|
o.R.DestinationEmailLogs = rel
|
|
}
|
|
|
|
if t.r.Organizations != nil {
|
|
rel := models.OrganizationSlice{}
|
|
for _, r := range t.r.Organizations {
|
|
related := r.o.BuildMany(r.number)
|
|
for _, rel := range related {
|
|
rel.R.EmailContacts = append(rel.R.EmailContacts, o)
|
|
}
|
|
rel = append(rel, related...)
|
|
}
|
|
o.R.Organizations = rel
|
|
}
|
|
}
|
|
|
|
// BuildSetter returns an *models.CommsEmailContactSetter
|
|
// this does nothing with the relationship templates
|
|
func (o CommsEmailContactTemplate) BuildSetter() *models.CommsEmailContactSetter {
|
|
m := &models.CommsEmailContactSetter{}
|
|
|
|
if o.Address != nil {
|
|
val := o.Address()
|
|
m.Address = omit.From(val)
|
|
}
|
|
if o.Confirmed != nil {
|
|
val := o.Confirmed()
|
|
m.Confirmed = omit.From(val)
|
|
}
|
|
if o.IsSubscribed != nil {
|
|
val := o.IsSubscribed()
|
|
m.IsSubscribed = omit.From(val)
|
|
}
|
|
if o.PublicID != nil {
|
|
val := o.PublicID()
|
|
m.PublicID = omit.From(val)
|
|
}
|
|
|
|
return m
|
|
}
|
|
|
|
// BuildManySetter returns an []*models.CommsEmailContactSetter
|
|
// this does nothing with the relationship templates
|
|
func (o CommsEmailContactTemplate) BuildManySetter(number int) []*models.CommsEmailContactSetter {
|
|
m := make([]*models.CommsEmailContactSetter, number)
|
|
|
|
for i := range m {
|
|
m[i] = o.BuildSetter()
|
|
}
|
|
|
|
return m
|
|
}
|
|
|
|
// Build returns an *models.CommsEmailContact
|
|
// Related objects are also created and placed in the .R field
|
|
// NOTE: Objects are not inserted into the database. Use CommsEmailContactTemplate.Create
|
|
func (o CommsEmailContactTemplate) Build() *models.CommsEmailContact {
|
|
m := &models.CommsEmailContact{}
|
|
|
|
if o.Address != nil {
|
|
m.Address = o.Address()
|
|
}
|
|
if o.Confirmed != nil {
|
|
m.Confirmed = o.Confirmed()
|
|
}
|
|
if o.IsSubscribed != nil {
|
|
m.IsSubscribed = o.IsSubscribed()
|
|
}
|
|
if o.PublicID != nil {
|
|
m.PublicID = o.PublicID()
|
|
}
|
|
|
|
o.setModelRels(m)
|
|
|
|
return m
|
|
}
|
|
|
|
// BuildMany returns an models.CommsEmailContactSlice
|
|
// Related objects are also created and placed in the .R field
|
|
// NOTE: Objects are not inserted into the database. Use CommsEmailContactTemplate.CreateMany
|
|
func (o CommsEmailContactTemplate) BuildMany(number int) models.CommsEmailContactSlice {
|
|
m := make(models.CommsEmailContactSlice, number)
|
|
|
|
for i := range m {
|
|
m[i] = o.Build()
|
|
}
|
|
|
|
return m
|
|
}
|
|
|
|
func ensureCreatableCommsEmailContact(m *models.CommsEmailContactSetter) {
|
|
if !(m.Address.IsValue()) {
|
|
val := random_string(nil)
|
|
m.Address = omit.From(val)
|
|
}
|
|
if !(m.Confirmed.IsValue()) {
|
|
val := random_bool(nil)
|
|
m.Confirmed = omit.From(val)
|
|
}
|
|
if !(m.IsSubscribed.IsValue()) {
|
|
val := random_bool(nil)
|
|
m.IsSubscribed = omit.From(val)
|
|
}
|
|
if !(m.PublicID.IsValue()) {
|
|
val := random_string(nil)
|
|
m.PublicID = omit.From(val)
|
|
}
|
|
}
|
|
|
|
// insertOptRels creates and inserts any optional the relationships on *models.CommsEmailContact
|
|
// according to the relationships in the template.
|
|
// any required relationship should have already exist on the model
|
|
func (o *CommsEmailContactTemplate) insertOptRels(ctx context.Context, exec bob.Executor, m *models.CommsEmailContact) error {
|
|
var err error
|
|
|
|
isDestinationEmailLogsDone, _ := commsEmailContactRelDestinationEmailLogsCtx.Value(ctx)
|
|
if !isDestinationEmailLogsDone && o.r.DestinationEmailLogs != nil {
|
|
ctx = commsEmailContactRelDestinationEmailLogsCtx.WithValue(ctx, true)
|
|
for _, r := range o.r.DestinationEmailLogs {
|
|
if r.o.alreadyPersisted {
|
|
m.R.DestinationEmailLogs = append(m.R.DestinationEmailLogs, r.o.Build())
|
|
} else {
|
|
rel0, err := r.o.CreateMany(ctx, exec, r.number)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
err = m.AttachDestinationEmailLogs(ctx, exec, rel0...)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
isOrganizationsDone, _ := commsEmailContactRelOrganizationsCtx.Value(ctx)
|
|
if !isOrganizationsDone && o.r.Organizations != nil {
|
|
ctx = commsEmailContactRelOrganizationsCtx.WithValue(ctx, true)
|
|
for _, r := range o.r.Organizations {
|
|
if r.o.alreadyPersisted {
|
|
m.R.Organizations = append(m.R.Organizations, r.o.Build())
|
|
} else {
|
|
rel1, err := r.o.CreateMany(ctx, exec, r.number)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
err = m.AttachOrganizations(ctx, exec, rel1...)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return err
|
|
}
|
|
|
|
// Create builds a commsEmailContact and inserts it into the database
|
|
// Relations objects are also inserted and placed in the .R field
|
|
func (o *CommsEmailContactTemplate) Create(ctx context.Context, exec bob.Executor) (*models.CommsEmailContact, error) {
|
|
var err error
|
|
opt := o.BuildSetter()
|
|
ensureCreatableCommsEmailContact(opt)
|
|
|
|
m, err := models.CommsEmailContacts.Insert(opt).One(ctx, exec)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if err := o.insertOptRels(ctx, exec, m); err != nil {
|
|
return nil, err
|
|
}
|
|
return m, err
|
|
}
|
|
|
|
// MustCreate builds a commsEmailContact and inserts it into the database
|
|
// Relations objects are also inserted and placed in the .R field
|
|
// panics if an error occurs
|
|
func (o *CommsEmailContactTemplate) MustCreate(ctx context.Context, exec bob.Executor) *models.CommsEmailContact {
|
|
m, err := o.Create(ctx, exec)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return m
|
|
}
|
|
|
|
// CreateOrFail builds a commsEmailContact and inserts it into the database
|
|
// Relations objects are also inserted and placed in the .R field
|
|
// It calls `tb.Fatal(err)` on the test/benchmark if an error occurs
|
|
func (o *CommsEmailContactTemplate) CreateOrFail(ctx context.Context, tb testing.TB, exec bob.Executor) *models.CommsEmailContact {
|
|
tb.Helper()
|
|
m, err := o.Create(ctx, exec)
|
|
if err != nil {
|
|
tb.Fatal(err)
|
|
return nil
|
|
}
|
|
return m
|
|
}
|
|
|
|
// CreateMany builds multiple commsEmailContacts and inserts them into the database
|
|
// Relations objects are also inserted and placed in the .R field
|
|
func (o CommsEmailContactTemplate) CreateMany(ctx context.Context, exec bob.Executor, number int) (models.CommsEmailContactSlice, error) {
|
|
var err error
|
|
m := make(models.CommsEmailContactSlice, number)
|
|
|
|
for i := range m {
|
|
m[i], err = o.Create(ctx, exec)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
return m, nil
|
|
}
|
|
|
|
// MustCreateMany builds multiple commsEmailContacts and inserts them into the database
|
|
// Relations objects are also inserted and placed in the .R field
|
|
// panics if an error occurs
|
|
func (o CommsEmailContactTemplate) MustCreateMany(ctx context.Context, exec bob.Executor, number int) models.CommsEmailContactSlice {
|
|
m, err := o.CreateMany(ctx, exec, number)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return m
|
|
}
|
|
|
|
// CreateManyOrFail builds multiple commsEmailContacts and inserts them into the database
|
|
// Relations objects are also inserted and placed in the .R field
|
|
// It calls `tb.Fatal(err)` on the test/benchmark if an error occurs
|
|
func (o CommsEmailContactTemplate) CreateManyOrFail(ctx context.Context, tb testing.TB, exec bob.Executor, number int) models.CommsEmailContactSlice {
|
|
tb.Helper()
|
|
m, err := o.CreateMany(ctx, exec, number)
|
|
if err != nil {
|
|
tb.Fatal(err)
|
|
return nil
|
|
}
|
|
return m
|
|
}
|
|
|
|
// CommsEmailContact has methods that act as mods for the CommsEmailContactTemplate
|
|
var CommsEmailContactMods commsEmailContactMods
|
|
|
|
type commsEmailContactMods struct{}
|
|
|
|
func (m commsEmailContactMods) RandomizeAllColumns(f *faker.Faker) CommsEmailContactMod {
|
|
return CommsEmailContactModSlice{
|
|
CommsEmailContactMods.RandomAddress(f),
|
|
CommsEmailContactMods.RandomConfirmed(f),
|
|
CommsEmailContactMods.RandomIsSubscribed(f),
|
|
CommsEmailContactMods.RandomPublicID(f),
|
|
}
|
|
}
|
|
|
|
// Set the model columns to this value
|
|
func (m commsEmailContactMods) Address(val string) CommsEmailContactMod {
|
|
return CommsEmailContactModFunc(func(_ context.Context, o *CommsEmailContactTemplate) {
|
|
o.Address = func() string { return val }
|
|
})
|
|
}
|
|
|
|
// Set the Column from the function
|
|
func (m commsEmailContactMods) AddressFunc(f func() string) CommsEmailContactMod {
|
|
return CommsEmailContactModFunc(func(_ context.Context, o *CommsEmailContactTemplate) {
|
|
o.Address = f
|
|
})
|
|
}
|
|
|
|
// Clear any values for the column
|
|
func (m commsEmailContactMods) UnsetAddress() CommsEmailContactMod {
|
|
return CommsEmailContactModFunc(func(_ context.Context, o *CommsEmailContactTemplate) {
|
|
o.Address = nil
|
|
})
|
|
}
|
|
|
|
// Generates a random value for the column using the given faker
|
|
// if faker is nil, a default faker is used
|
|
func (m commsEmailContactMods) RandomAddress(f *faker.Faker) CommsEmailContactMod {
|
|
return CommsEmailContactModFunc(func(_ context.Context, o *CommsEmailContactTemplate) {
|
|
o.Address = func() string {
|
|
return random_string(f)
|
|
}
|
|
})
|
|
}
|
|
|
|
// Set the model columns to this value
|
|
func (m commsEmailContactMods) Confirmed(val bool) CommsEmailContactMod {
|
|
return CommsEmailContactModFunc(func(_ context.Context, o *CommsEmailContactTemplate) {
|
|
o.Confirmed = func() bool { return val }
|
|
})
|
|
}
|
|
|
|
// Set the Column from the function
|
|
func (m commsEmailContactMods) ConfirmedFunc(f func() bool) CommsEmailContactMod {
|
|
return CommsEmailContactModFunc(func(_ context.Context, o *CommsEmailContactTemplate) {
|
|
o.Confirmed = f
|
|
})
|
|
}
|
|
|
|
// Clear any values for the column
|
|
func (m commsEmailContactMods) UnsetConfirmed() CommsEmailContactMod {
|
|
return CommsEmailContactModFunc(func(_ context.Context, o *CommsEmailContactTemplate) {
|
|
o.Confirmed = nil
|
|
})
|
|
}
|
|
|
|
// Generates a random value for the column using the given faker
|
|
// if faker is nil, a default faker is used
|
|
func (m commsEmailContactMods) RandomConfirmed(f *faker.Faker) CommsEmailContactMod {
|
|
return CommsEmailContactModFunc(func(_ context.Context, o *CommsEmailContactTemplate) {
|
|
o.Confirmed = func() bool {
|
|
return random_bool(f)
|
|
}
|
|
})
|
|
}
|
|
|
|
// Set the model columns to this value
|
|
func (m commsEmailContactMods) IsSubscribed(val bool) CommsEmailContactMod {
|
|
return CommsEmailContactModFunc(func(_ context.Context, o *CommsEmailContactTemplate) {
|
|
o.IsSubscribed = func() bool { return val }
|
|
})
|
|
}
|
|
|
|
// Set the Column from the function
|
|
func (m commsEmailContactMods) IsSubscribedFunc(f func() bool) CommsEmailContactMod {
|
|
return CommsEmailContactModFunc(func(_ context.Context, o *CommsEmailContactTemplate) {
|
|
o.IsSubscribed = f
|
|
})
|
|
}
|
|
|
|
// Clear any values for the column
|
|
func (m commsEmailContactMods) UnsetIsSubscribed() CommsEmailContactMod {
|
|
return CommsEmailContactModFunc(func(_ context.Context, o *CommsEmailContactTemplate) {
|
|
o.IsSubscribed = nil
|
|
})
|
|
}
|
|
|
|
// Generates a random value for the column using the given faker
|
|
// if faker is nil, a default faker is used
|
|
func (m commsEmailContactMods) RandomIsSubscribed(f *faker.Faker) CommsEmailContactMod {
|
|
return CommsEmailContactModFunc(func(_ context.Context, o *CommsEmailContactTemplate) {
|
|
o.IsSubscribed = func() bool {
|
|
return random_bool(f)
|
|
}
|
|
})
|
|
}
|
|
|
|
// Set the model columns to this value
|
|
func (m commsEmailContactMods) PublicID(val string) CommsEmailContactMod {
|
|
return CommsEmailContactModFunc(func(_ context.Context, o *CommsEmailContactTemplate) {
|
|
o.PublicID = func() string { return val }
|
|
})
|
|
}
|
|
|
|
// Set the Column from the function
|
|
func (m commsEmailContactMods) PublicIDFunc(f func() string) CommsEmailContactMod {
|
|
return CommsEmailContactModFunc(func(_ context.Context, o *CommsEmailContactTemplate) {
|
|
o.PublicID = f
|
|
})
|
|
}
|
|
|
|
// Clear any values for the column
|
|
func (m commsEmailContactMods) UnsetPublicID() CommsEmailContactMod {
|
|
return CommsEmailContactModFunc(func(_ context.Context, o *CommsEmailContactTemplate) {
|
|
o.PublicID = nil
|
|
})
|
|
}
|
|
|
|
// Generates a random value for the column using the given faker
|
|
// if faker is nil, a default faker is used
|
|
func (m commsEmailContactMods) RandomPublicID(f *faker.Faker) CommsEmailContactMod {
|
|
return CommsEmailContactModFunc(func(_ context.Context, o *CommsEmailContactTemplate) {
|
|
o.PublicID = func() string {
|
|
return random_string(f)
|
|
}
|
|
})
|
|
}
|
|
|
|
func (m commsEmailContactMods) WithParentsCascading() CommsEmailContactMod {
|
|
return CommsEmailContactModFunc(func(ctx context.Context, o *CommsEmailContactTemplate) {
|
|
if isDone, _ := commsEmailContactWithParentsCascadingCtx.Value(ctx); isDone {
|
|
return
|
|
}
|
|
ctx = commsEmailContactWithParentsCascadingCtx.WithValue(ctx, true)
|
|
})
|
|
}
|
|
|
|
func (m commsEmailContactMods) WithDestinationEmailLogs(number int, related *CommsEmailLogTemplate) CommsEmailContactMod {
|
|
return CommsEmailContactModFunc(func(ctx context.Context, o *CommsEmailContactTemplate) {
|
|
o.r.DestinationEmailLogs = []*commsEmailContactRDestinationEmailLogsR{{
|
|
number: number,
|
|
o: related,
|
|
}}
|
|
})
|
|
}
|
|
|
|
func (m commsEmailContactMods) WithNewDestinationEmailLogs(number int, mods ...CommsEmailLogMod) CommsEmailContactMod {
|
|
return CommsEmailContactModFunc(func(ctx context.Context, o *CommsEmailContactTemplate) {
|
|
related := o.f.NewCommsEmailLogWithContext(ctx, mods...)
|
|
m.WithDestinationEmailLogs(number, related).Apply(ctx, o)
|
|
})
|
|
}
|
|
|
|
func (m commsEmailContactMods) AddDestinationEmailLogs(number int, related *CommsEmailLogTemplate) CommsEmailContactMod {
|
|
return CommsEmailContactModFunc(func(ctx context.Context, o *CommsEmailContactTemplate) {
|
|
o.r.DestinationEmailLogs = append(o.r.DestinationEmailLogs, &commsEmailContactRDestinationEmailLogsR{
|
|
number: number,
|
|
o: related,
|
|
})
|
|
})
|
|
}
|
|
|
|
func (m commsEmailContactMods) AddNewDestinationEmailLogs(number int, mods ...CommsEmailLogMod) CommsEmailContactMod {
|
|
return CommsEmailContactModFunc(func(ctx context.Context, o *CommsEmailContactTemplate) {
|
|
related := o.f.NewCommsEmailLogWithContext(ctx, mods...)
|
|
m.AddDestinationEmailLogs(number, related).Apply(ctx, o)
|
|
})
|
|
}
|
|
|
|
func (m commsEmailContactMods) AddExistingDestinationEmailLogs(existingModels ...*models.CommsEmailLog) CommsEmailContactMod {
|
|
return CommsEmailContactModFunc(func(ctx context.Context, o *CommsEmailContactTemplate) {
|
|
for _, em := range existingModels {
|
|
o.r.DestinationEmailLogs = append(o.r.DestinationEmailLogs, &commsEmailContactRDestinationEmailLogsR{
|
|
o: o.f.FromExistingCommsEmailLog(em),
|
|
})
|
|
}
|
|
})
|
|
}
|
|
|
|
func (m commsEmailContactMods) WithoutDestinationEmailLogs() CommsEmailContactMod {
|
|
return CommsEmailContactModFunc(func(ctx context.Context, o *CommsEmailContactTemplate) {
|
|
o.r.DestinationEmailLogs = nil
|
|
})
|
|
}
|
|
|
|
func (m commsEmailContactMods) WithOrganizations(number int, related *OrganizationTemplate) CommsEmailContactMod {
|
|
return CommsEmailContactModFunc(func(ctx context.Context, o *CommsEmailContactTemplate) {
|
|
o.r.Organizations = []*commsEmailContactROrganizationsR{{
|
|
number: number,
|
|
o: related,
|
|
}}
|
|
})
|
|
}
|
|
|
|
func (m commsEmailContactMods) WithNewOrganizations(number int, mods ...OrganizationMod) CommsEmailContactMod {
|
|
return CommsEmailContactModFunc(func(ctx context.Context, o *CommsEmailContactTemplate) {
|
|
related := o.f.NewOrganizationWithContext(ctx, mods...)
|
|
m.WithOrganizations(number, related).Apply(ctx, o)
|
|
})
|
|
}
|
|
|
|
func (m commsEmailContactMods) AddOrganizations(number int, related *OrganizationTemplate) CommsEmailContactMod {
|
|
return CommsEmailContactModFunc(func(ctx context.Context, o *CommsEmailContactTemplate) {
|
|
o.r.Organizations = append(o.r.Organizations, &commsEmailContactROrganizationsR{
|
|
number: number,
|
|
o: related,
|
|
})
|
|
})
|
|
}
|
|
|
|
func (m commsEmailContactMods) AddNewOrganizations(number int, mods ...OrganizationMod) CommsEmailContactMod {
|
|
return CommsEmailContactModFunc(func(ctx context.Context, o *CommsEmailContactTemplate) {
|
|
related := o.f.NewOrganizationWithContext(ctx, mods...)
|
|
m.AddOrganizations(number, related).Apply(ctx, o)
|
|
})
|
|
}
|
|
|
|
func (m commsEmailContactMods) AddExistingOrganizations(existingModels ...*models.Organization) CommsEmailContactMod {
|
|
return CommsEmailContactModFunc(func(ctx context.Context, o *CommsEmailContactTemplate) {
|
|
for _, em := range existingModels {
|
|
o.r.Organizations = append(o.r.Organizations, &commsEmailContactROrganizationsR{
|
|
o: o.f.FromExistingOrganization(em),
|
|
})
|
|
}
|
|
})
|
|
}
|
|
|
|
func (m commsEmailContactMods) WithoutOrganizations() CommsEmailContactMod {
|
|
return CommsEmailContactModFunc(func(ctx context.Context, o *CommsEmailContactTemplate) {
|
|
o.r.Organizations = nil
|
|
})
|
|
}
|