2020-02-24 16:26:01 +00:00
|
|
|
package database
|
|
|
|
|
|
|
|
import "github.com/hunterlong/statping/types"
|
|
|
|
|
|
|
|
type IncidentObj struct {
|
|
|
|
*types.Incident
|
2020-02-25 07:41:28 +00:00
|
|
|
o *Object
|
2020-02-24 16:26:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func Incident(id int64) (*IncidentObj, error) {
|
|
|
|
var incident types.Incident
|
2020-02-25 07:41:28 +00:00
|
|
|
query := database.Incidents().Where("id = ?", id)
|
|
|
|
finder := query.Find(&incident)
|
|
|
|
return &IncidentObj{Incident: &incident, o: wrapObject(id, &incident, query)}, finder.Error()
|
|
|
|
}
|
|
|
|
|
|
|
|
func AllIncidents() []*types.Incident {
|
|
|
|
var incidents []*types.Incident
|
|
|
|
database.Incidents().Find(&incidents)
|
|
|
|
return incidents
|
|
|
|
}
|
|
|
|
|
|
|
|
func (i *IncidentObj) Updates() []*types.IncidentUpdate {
|
|
|
|
var incidents []*types.IncidentUpdate
|
|
|
|
database.IncidentUpdates().Where("incident = ?", i.Id).Find(&incidents)
|
|
|
|
return incidents
|
|
|
|
}
|
|
|
|
|
|
|
|
func (i *IncidentObj) object() *Object {
|
|
|
|
return i.o
|
2020-02-24 16:26:01 +00:00
|
|
|
}
|