Zippytal-Node/zoneNotificationsDBHandler.go

42 lines
967 B
Go

package localserver
import (
"path/filepath"
sync "sync"
"github.com/dgraph-io/badger/v3"
)
type ZoneNotification struct {
ID string
Type string
Description string
Recipients []string
}
type ZoneNotificationDBHandler struct {
ZoneID string
db func(func(*badger.DB) (err error)) (err error)
lock *sync.RWMutex
}
func NewZoneNotificationDBHandler(zoneId string) (zoneFilesDBHandler *ZoneNotificationDBHandler, err error) {
zoneFilesDBHandler = &ZoneNotificationDBHandler{
db: func(f func(*badger.DB) (err error)) (err error) {
path := filepath.Join(dataPath, "data", "zones", zoneId, "notifications")
db, err := badger.Open(badger.DefaultOptions(path).WithLogger(dbLogger))
if err != nil {
return
}
defer db.Close()
err = f(db)
return
},
ZoneID: zoneId,
lock: new(sync.RWMutex),
}
return
}
//Todo: implement pull notification module for beta only push notification are enabled for simplicity