Support Reminder events

Move code to schedule to have event independent from NotificationPlatform
This commit is contained in:
Mo Tarbin 2025-02-10 01:44:42 -05:00
parent 04d1894aea
commit 80afab3bc0
7 changed files with 61 additions and 28 deletions

View file

@ -1,6 +1,11 @@
package model
import "time"
import (
"database/sql/driver"
"encoding/json"
"errors"
"time"
)
type Notification struct {
ID int `json:"id" gorm:"primaryKey"`
@ -13,7 +18,7 @@ type Notification struct {
TypeID NotificationPlatform `json:"type" gorm:"column:type"`
ScheduledFor time.Time `json:"scheduled_for" gorm:"column:scheduled_for;index"`
CreatedAt time.Time `json:"created_at" gorm:"column:created_at"`
RawEvent interface{} `json:"raw_event" gorm:"column:raw_event;type:jsonb"`
RawEvent JSONB `json:"raw_event" gorm:"column:raw_event;type:jsonb"`
}
type NotificationDetails struct {
Notification
@ -32,3 +37,24 @@ const (
NotificationPlatformTelegram
NotificationPlatformPushover
)
type JSONB map[string]interface{}
func (j JSONB) Value() (driver.Value, error) {
value, err := json.Marshal(j)
if err != nil {
return nil, err
}
return string(value), nil
}
func (j *JSONB) Scan(value interface{}) error {
switch v := value.(type) {
case []byte:
return json.Unmarshal(v, j)
case string:
return json.Unmarshal([]byte(v), j)
default:
return errors.New("type assertion to []byte or string failed")
}
}