From 945beb79e5ed72792e14ded58a04e36efcc108e2 Mon Sep 17 00:00:00 2001 From: Rhythm <35167328+kRhythm@users.noreply.github.com> Date: Wed, 8 Dec 2021 14:27:52 +0530 Subject: [PATCH] added skip --- handlers/downtimes.go | 6 ++++++ types/downtimes/database.go | 14 +++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/handlers/downtimes.go b/handlers/downtimes.go index 7e04a8fd..ba374577 100644 --- a/handlers/downtimes.go +++ b/handlers/downtimes.go @@ -39,6 +39,12 @@ func convertToMap(query url.Values) map[string]string{ if query.Get("type")!= "" { vars["type"] = query.Get("type") } + if query.Get("skip")!= "" { + vars["skip"] = query.Get("skip") + } + if query.Get("count")!= "" { + vars["count"] = query.Get("count") + } return vars } func apiAllDowntimes(w http.ResponseWriter, r *http.Request) { diff --git a/types/downtimes/database.go b/types/downtimes/database.go index e2c609f2..e1166e9f 100644 --- a/types/downtimes/database.go +++ b/types/downtimes/database.go @@ -68,17 +68,14 @@ func ConvertToUnixTime(str string) (time.Time,error){ tm := time.Unix(i, 0) return tm,nil } -type invalidTimeDurationError struct{} -func (m *invalidTimeDurationError) Error() string { - return "invalid time duration" -} func FindAll(vars map[string]string ) (*[]Downtime, error) { var downtime []Downtime var start time.Time var end time.Time var err error var count int64 + var skip int64 st,err1 := vars["start"] en,err2 := vars["end"] if err1 && err2 && (en > st){ @@ -117,7 +114,14 @@ func FindAll(vars map[string]string ) (*[]Downtime, error) { }else { count = 20 } - q = q.Order("id ASC ").Find(&downtime) + skp,err6:=vars["skip"] + if err6{ + skip,err = strconv.ParseInt(skp,10,64) + }else { + skip = 0 + } + q = q.Order("id ASC ") + q = q.Limit((int)(count)).Offset((int)(skip)).Find(&downtime) return &downtime, q.Error() } func (c *Downtime) Create() error {