From 1490cd58a2d8725331833d4c730d5ffc1595ccd4 Mon Sep 17 00:00:00 2001 From: SammyOina Date: Tue, 1 Aug 2023 12:58:44 +0300 Subject: [PATCH] fix date filter bug Signed-off-by: SammyOina --- api/requests.go | 2 +- timescale/timescale.go | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/api/requests.go b/api/requests.go index ee8fef3..537b01b 100644 --- a/api/requests.go +++ b/api/requests.go @@ -52,7 +52,7 @@ func (req listTelemetryReq) validate() error { return ErrLimitSize } - if req.to.Before(req.from) { + if !req.from.IsZero() && req.to.Before(req.from) { return ErrInvalidDateRange } diff --git a/timescale/timescale.go b/timescale/timescale.go index 929da47..c0efcd4 100644 --- a/timescale/timescale.go +++ b/timescale/timescale.go @@ -153,15 +153,14 @@ func generateQuery(filters callhome.TelemetryFilters) (string, map[string]interf var queries []string params := make(map[string]interface{}) - switch { - case !filters.From.IsZero(): + if !filters.From.IsZero() { queries = append(queries, "time >= :from") params["from"] = filters.From - case !filters.To.IsZero(): + } + if !filters.To.IsZero() { queries = append(queries, "time <= :to") params["to"] = filters.To } - if filters.Country != "" { queries = append(queries, "country = :country") params["country"] = filters.Country