Add Event Producer
Update User to carry webhook from circle if assigned Refactor notification handling and update models for webhook support
This commit is contained in:
parent
44cb5501dd
commit
04d1894aea
17 changed files with 351 additions and 101 deletions
|
@ -3,35 +3,32 @@ package model
|
|||
import "time"
|
||||
|
||||
type Notification struct {
|
||||
ID int `json:"id" gorm:"primaryKey"`
|
||||
ChoreID int `json:"chore_id" gorm:"column:chore_id"`
|
||||
UserID int `json:"user_id" gorm:"column:user_id"`
|
||||
TargetID string `json:"target_id" gorm:"column:target_id"`
|
||||
Text string `json:"text" gorm:"column:text"`
|
||||
IsSent bool `json:"is_sent" gorm:"column:is_sent;index;default:false"`
|
||||
TypeID NotificationType `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"`
|
||||
ID int `json:"id" gorm:"primaryKey"`
|
||||
ChoreID int `json:"chore_id" gorm:"column:chore_id"`
|
||||
CircleID int `json:"circle_id" gorm:"column:circle_id"`
|
||||
UserID int `json:"user_id" gorm:"column:user_id"`
|
||||
TargetID string `json:"target_id" gorm:"column:target_id"`
|
||||
Text string `json:"text" gorm:"column:text"`
|
||||
IsSent bool `json:"is_sent" gorm:"column:is_sent;index;default:false"`
|
||||
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"`
|
||||
}
|
||||
type NotificationDetails struct {
|
||||
Notification
|
||||
WebhookURL *string `json:"webhook_url" gorm:"column:webhook_url;<-:null"` // read-only, will only be used if webhook enabled
|
||||
|
||||
}
|
||||
|
||||
func (n *Notification) IsValid() bool {
|
||||
switch n.TypeID {
|
||||
case NotificationTypeTelegram, NotificationTypePushover:
|
||||
if n.TargetID == "" {
|
||||
return false
|
||||
} else if n.Text == "0" {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
type NotificationType int8
|
||||
type NotificationPlatform int8
|
||||
|
||||
const (
|
||||
NotificationTypeNone NotificationType = iota
|
||||
NotificationTypeTelegram
|
||||
NotificationTypePushover
|
||||
NotificationPlatformNone NotificationPlatform = iota
|
||||
NotificationPlatformTelegram
|
||||
NotificationPlatformPushover
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue