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)