added time

This commit is contained in:
Darko Luketic
2018-04-03 22:11:59 +02:00
parent 054dc5afce
commit f89589d0db
8 changed files with 74 additions and 14 deletions

View File

@ -3,6 +3,8 @@ package handler
import (
"strconv"
"time"
"git.icod.de/dalu/refdata/api/repo"
"git.icod.de/dalu/refdata/model"
"github.com/gin-gonic/gin"
@ -57,6 +59,7 @@ func (h *Handler) ListData(cx *gin.Context) {
age := cx.Query("age")
price := cx.Query("price")
enabled := cx.Query("enabled")
when := cx.Query("when")
// string
if name == "1" {
@ -109,6 +112,7 @@ func (h *Handler) ListData(cx *gin.Context) {
if price == "1" {
p.Price = true
p.PriceQuery = repo.DataPriceQuery{}
p.PriceQuery.Operation = cx.Query("price.operation")
from, e := strconv.ParseFloat(cx.Query("age.from"), 64)
if e != nil {
cx.AbortWithStatus(400)
@ -136,6 +140,25 @@ func (h *Handler) ListData(cx *gin.Context) {
}
}
// time
if when == "1" {
p.When = true
p.WhenQuery = repo.DataWhenQuery{}
p.WhenQuery.Operation = cx.Query("when.operation")
from, e := time.Parse(time.RFC3339, cx.Query("when.from"))
if e != nil {
cx.AbortWithStatus(400)
return
}
to, e := time.Parse(time.RFC3339, cx.Query("when.to"))
if e != nil {
cx.AbortWithStatus(400)
return
}
p.WhenQuery.From = from
p.WhenQuery.To = to
}
m, e := h.dataRepo.List(p)
if e != nil {
cx.AbortWithError(500, e)