package factories import ( "github.com/icrowley/fake" "rocketgit.ru/rsmon/worker/app/models" ) // NotificationFactory provides functionality. func NotificationFactory(account *models.Account, contactIDs, groupIDs []int64, alertDelay int64, notifyRestore bool) models.Notification { BeforeExpiration := int64(3600) notification := models.Notification{ Name: fake.Company(), ContactIDs: contactIDs, GroupIDs: groupIDs, AlertDelay: &alertDelay, NotifyDown: true, NotifyRestore: notifyRestore, BeforeExpiration: &BeforeExpiration, } if account == nil { c := AccountFactory() account = &c } notification.Account = account notification.AccountID = account.ID return notification } // PersistedNotification provides functionality. func PersistedNotification(account *models.Account, contactIDs, groupIDs []int64, alertDelay int64, notifyRestore bool) models.Notification { //nolint:lll notification := NotificationFactory(account, contactIDs, groupIDs, alertDelay, notifyRestore) if notification.Account.ID == 0 { err := models.DB().Save(¬ification.Account).Error if err != nil { panic(err) } notification.AccountID = notification.Account.ID } err := models.DB().Save(¬ification).Error if err != nil { panic(err) } err = notification.PersistRelations() if err != nil { panic(err) } return notification }