mirror of https://github.com/statping/statping
notifier API routes
parent
7a5685307a
commit
4cfa5c96b9
|
@ -48,21 +48,21 @@ type Notification struct {
|
|||
ApiSecret string `gorm:"not null;column:api_secret" json:"api_secret,omitempty"`
|
||||
Enabled types.NullBool `gorm:"column:enabled;type:boolean;default:false" json:"enabled"`
|
||||
Limits int `gorm:"not null;column:limits" json:"limits"`
|
||||
Removable bool `gorm:"column:removable" json:"-"`
|
||||
Removable bool `gorm:"column:removable" json:"removeable"`
|
||||
CreatedAt time.Time `gorm:"column:created_at" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"column:updated_at" json:"updated_at"`
|
||||
Form []NotificationForm `gorm:"-" json:"form"`
|
||||
logs []*NotificationLog `gorm:"-" json:"-"`
|
||||
logs []*NotificationLog `gorm:"-" json:"logs"`
|
||||
Title string `gorm:"-" json:"title"`
|
||||
Description string `gorm:"-" json:"description"`
|
||||
Author string `gorm:"-" json:"-"`
|
||||
AuthorUrl string `gorm:"-" json:"-"`
|
||||
Icon string `gorm:"-" json:"-"`
|
||||
Author string `gorm:"-" json:"author"`
|
||||
AuthorUrl string `gorm:"-" json:"author_url"`
|
||||
Icon string `gorm:"-" json:"icon"`
|
||||
Delay time.Duration `gorm:"-" json:"delay"`
|
||||
Queue []*QueueData `gorm:"-" json:"-"`
|
||||
Queue []*QueueData `gorm:"-" json:"queue"`
|
||||
Running chan bool `gorm:"-" json:"-"`
|
||||
Online bool `gorm:"-" json:"-"`
|
||||
testable bool `gorm:"-" json:"-"`
|
||||
Online bool `gorm:"-" json:"online"`
|
||||
testable bool `gorm:"-" json:"testable"`
|
||||
}
|
||||
|
||||
// QueueData is the struct for the messaging queue with service
|
||||
|
@ -73,19 +73,19 @@ type QueueData struct {
|
|||
|
||||
// NotificationForm contains the HTML fields for each variable/input you want the notifier to accept.
|
||||
type NotificationForm struct {
|
||||
Type string // the html input type (text, password, email)
|
||||
Title string // include a title for ease of use
|
||||
Placeholder string // add a placeholder for the input
|
||||
DbField string // true variable key for input
|
||||
SmallText string // insert small text under a html input
|
||||
Required bool // require this input on the html form
|
||||
Type string `json:"type"` // the html input type (text, password, email)
|
||||
Title string `json:"title"` // include a title for ease of use
|
||||
Placeholder string `json:"placeholder"` // add a placeholder for the input
|
||||
DbField string `json:"field"` // true variable key for input
|
||||
SmallText string `json:"small_text"` // insert small text under a html input
|
||||
Required bool `json:"required"` // require this input on the html form
|
||||
}
|
||||
|
||||
// NotificationLog contains the normalized message from previously sent notifications
|
||||
type NotificationLog struct {
|
||||
Message string
|
||||
Time utils.Timestamp
|
||||
Timestamp time.Time
|
||||
Message string `json:"message"`
|
||||
Time utils.Timestamp `json:"time"`
|
||||
Timestamp time.Time `json:"timestamp"`
|
||||
}
|
||||
|
||||
// AddQueue will add any type of interface (json, string, struct, etc) into the Notifiers queue
|
||||
|
|
|
@ -479,6 +479,20 @@ func apiMessageUpdateHandler(w http.ResponseWriter, r *http.Request) {
|
|||
json.NewEncoder(w).Encode(output)
|
||||
}
|
||||
|
||||
func apiNotifiersHandler(w http.ResponseWriter, r *http.Request) {
|
||||
if !IsAuthenticated(r) {
|
||||
http.Redirect(w, r, "/", http.StatusSeeOther)
|
||||
return
|
||||
}
|
||||
var notifiers []*notifier.Notification
|
||||
for _, n := range core.CoreApp.Notifications {
|
||||
notif := n.(notifier.Notifier)
|
||||
notifiers = append(notifiers, notif.Select())
|
||||
}
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(notifiers)
|
||||
}
|
||||
|
||||
func isAPIAuthorized(r *http.Request) bool {
|
||||
if os.Getenv("GO_ENV") == "test" {
|
||||
return true
|
||||
|
|
|
@ -122,6 +122,7 @@ func Router() *mux.Router {
|
|||
r.Handle("/api/users/{id}", http.HandlerFunc(apiUserDeleteHandler)).Methods("DELETE")
|
||||
|
||||
// API NOTIFIER Routes
|
||||
r.Handle("/api/notifiers", http.HandlerFunc(apiNotifiersHandler)).Methods("GET")
|
||||
r.Handle("/api/notifier/{notifier}", http.HandlerFunc(apiNotifierGetHandler)).Methods("GET")
|
||||
r.Handle("/api/notifier/{notifier}", http.HandlerFunc(apiNotifierUpdateHandler)).Methods("POST")
|
||||
|
||||
|
|
Loading…
Reference in New Issue