From 426a4cbd8346b88987360cce01a2353b3ad98381 Mon Sep 17 00:00:00 2001 From: Darko Luketic <2694548+dalu@users.noreply.github.com> Date: Tue, 3 Apr 2018 23:03:46 +0200 Subject: [PATCH] added time --- api/repo/data.go | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/api/repo/data.go b/api/repo/data.go index a61ee5a..8809594 100644 --- a/api/repo/data.go +++ b/api/repo/data.go @@ -3,7 +3,6 @@ package repo import ( "errors" "fmt" - "time" "git.icod.de/dalu/refdata/model" @@ -200,6 +199,30 @@ func (r *DataRepository) List(p *DataParams) ([]*model.Data, error) { q["enabled"] = p.EnabledQuery.Query } + // time + if p.When { + switch p.WhenQuery.Operation { + case "eq": + q["when"] = p.WhenQuery.From + case "gt": + q["when"] = bson.M{"$gt": p.WhenQuery.From} + case "gte": + q["when"] = bson.M{"$gte": p.WhenQuery.From} + case "lt": + q["when"] = bson.M{"$lt": p.WhenQuery.To} + case "lte": + q["when"] = bson.M{"$lte": p.WhenQuery.To} + case "gt-lt": + q["when"] = bson.M{"$gt": p.WhenQuery.From, "$lt": p.WhenQuery.To} + case "gte-lte": + q["when"] = bson.M{"$gte": p.WhenQuery.From, "$lte": p.WhenQuery.To} + case "gte-lt": + q["when"] = bson.M{"$gte": p.WhenQuery.From, "$lt": p.WhenQuery.To} + case "gt-lte": + q["when"] = bson.M{"$gt": p.WhenQuery.From, "$lte": p.WhenQuery.To} + } + } + var m []*model.Data rq := c.Find(q)