mirror of https://github.com/statping/statping
overlapping intervals (#24)
* overlapping intervals * commentted changes * fmted Co-authored-by: Rhythm <35167328+kRhythm@users.noreply.github.com>pull/1097/head
parent
932f3fdb33
commit
c43416241a
|
@ -108,6 +108,12 @@ func apiCreateDowntimeHandler(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if downtime.CheckOverlapping() {
|
||||
err := fmt.Errorf("downtime interval overlapping error")
|
||||
sendErrorJson(err, w, r)
|
||||
return
|
||||
}
|
||||
|
||||
s, err := services.FindFirstFromDB(downtime.ServiceId)
|
||||
if err != nil {
|
||||
sendErrorJson(err, w, r)
|
||||
|
|
|
@ -74,6 +74,20 @@ func FindLatestDowntimeOfService(service int64) Downtime {
|
|||
return downtime
|
||||
}
|
||||
|
||||
func (c *Downtime) CheckOverlapping() bool {
|
||||
var downtimes []Downtime
|
||||
q := db.Where("service = ?", c.ServiceId)
|
||||
q = q.Where("\"end\" IS NULL or \"end\" >= ?", c.Start)
|
||||
if c.End != nil {
|
||||
q = q.Where("start <= ?", c.End)
|
||||
}
|
||||
q = q.Find(&downtimes)
|
||||
if len(downtimes) > 0 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func FindAll(vars map[string]string) (*[]Downtime, error) {
|
||||
var downtime []Downtime
|
||||
var start time.Time
|
||||
|
|
Loading…
Reference in New Issue