statping/communication.go

82 lines
1.4 KiB
Go
Raw Normal View History

2018-06-23 00:10:37 +00:00
package main
2018-06-23 04:17:57 +00:00
import (
2018-06-23 08:42:50 +00:00
"fmt"
2018-06-23 04:17:57 +00:00
"github.com/hunterlong/statup/types"
"time"
2018-06-23 00:10:37 +00:00
)
2018-06-23 04:17:57 +00:00
func LoadDefaultCommunications() {
emailer := SelectCommunication(1)
2018-06-23 08:42:50 +00:00
fmt.Println(emailer)
LoadMailer(emailer)
go EmailerQueue()
2018-06-23 00:10:37 +00:00
}
2018-06-23 04:17:57 +00:00
func LoadComms() {
for _, c := range core.Communications {
2018-06-23 00:10:37 +00:00
if c.Enabled {
2018-06-23 04:17:57 +00:00
2018-06-23 00:10:37 +00:00
}
}
}
2018-06-23 04:17:57 +00:00
func Run(c *types.Communication) {
2018-06-23 00:10:37 +00:00
2018-06-23 04:17:57 +00:00
sample := &types.Email{
To: "info@socialeck.com",
Subject: "Test Email from Statup",
}
2018-06-23 08:42:50 +00:00
AddEmail(sample)
2018-06-23 00:10:37 +00:00
}
2018-06-23 04:17:57 +00:00
func SelectAllCommunications() ([]*types.Communication, error) {
var c []*types.Communication
2018-06-23 00:10:37 +00:00
col := dbSession.Collection("communication").Find()
err := col.All(&c)
2018-06-23 04:17:57 +00:00
core.Communications = c
2018-06-23 00:10:37 +00:00
return c, err
}
2018-06-23 04:17:57 +00:00
func Create(c *types.Communication) (int64, error) {
2018-06-23 00:10:37 +00:00
c.CreatedAt = time.Now()
uuid, err := dbSession.Collection("communication").Insert(c)
2018-06-23 04:17:57 +00:00
if err != nil {
panic(err)
}
2018-06-23 00:10:37 +00:00
if uuid == nil {
return 0, err
}
c.Id = uuid.(int64)
2018-06-23 05:59:29 +00:00
if core != nil {
core.Communications = append(core.Communications, c)
}
2018-06-23 00:10:37 +00:00
return uuid.(int64), err
}
2018-06-23 04:17:57 +00:00
func Disable(c *types.Communication) {
2018-06-23 00:10:37 +00:00
c.Enabled = false
2018-06-23 04:17:57 +00:00
Update(c)
2018-06-23 00:10:37 +00:00
}
2018-06-23 04:17:57 +00:00
func Enable(c *types.Communication) {
2018-06-23 00:10:37 +00:00
c.Enabled = true
2018-06-23 04:17:57 +00:00
Update(c)
2018-06-23 00:10:37 +00:00
}
2018-06-23 04:17:57 +00:00
func Update(c *types.Communication) *types.Communication {
2018-06-23 00:10:37 +00:00
col := dbSession.Collection("communication").Find("id", c.Id)
col.Update(c)
return c
}
2018-06-23 04:17:57 +00:00
func SelectCommunication(id int64) *types.Communication {
for _, c := range core.Communications {
2018-06-23 00:10:37 +00:00
if c.Id == id {
return c
}
}
return nil
}