added some changes

pull/1067/head
Rhythm 2021-12-20 01:48:02 +05:30
parent 2fe44c51e2
commit eeca8c9a77
2 changed files with 47 additions and 2 deletions

View File

@ -8,10 +8,12 @@ import (
"github.com/statping/statping/types/failures"
"github.com/statping/statping/types/hits"
"github.com/statping/statping/types/services"
"github.com/statping/statping/types/downtimes"
"github.com/statping/statping/utils"
"net/http"
"net/url"
"sort"
"strconv"
"time"
)
@ -40,6 +42,38 @@ func findService(r *http.Request) (*services.Service, error) {
return servicer, nil
}
func ConvertToUnixTime(str string) (time.Time,error){
i, err := strconv.ParseInt(str, 10, 64)
var t time.Time
if err != nil {
return t,err
}
tm := time.Unix(i, 0)
return tm,nil
}
func findServiceStatus(t string,s services.Service) string{
var timeVar time.Time
if t == ""{
timeVar = time.Now()
}else{
var err error
timeVar,err = ConvertToUnixTime(t)
if err != nil{
return ""
}
}
var downtimes []Downtime
start := time.Time{}
end := timeVar
q := db.Where("start BETWEEN ? AND ?", start, end)
return ""
}
func findPublicSubService(r *http.Request, service *services.Service) (*services.Service, error) {
vars := mux.Vars(r)
id := utils.ToInt(vars["sub_id"])
@ -522,17 +556,21 @@ func convertToMap(query url.Values) map[string]string{
return vars
}
func apiAllServicesHandler(r *http.Request) interface{} {
query := r.URL.Query()
timeVar := time.Now().Unix()
var t string
if query.Get("time") != ""{
timeVar =
t = query.Get("time")
}
var srvs []services.Service
for _, v := range services.AllInOrder() {
if !v.Public.Bool && !IsUser(r) {
continue
}
serviceStatus :=findServiceStatus(t,v)
srvs = append(srvs, v)
}
return srvs

View File

@ -58,6 +58,13 @@ func FindByService(service int64, start time.Time, end time.Time) (*[]Downtime,
return &downtime, q.Error()
}
func FindAllByService(service int64) (*[]Downtime, error) {
var downtime []Downtime
q := db.Where("service = ? ", service)
q = q.Order("id ASC ").Find(&downtime)
return &downtime, q.Error()
}
func (c *Downtime) Create() error {
q := db.Create(c)
return q.Error()