added time
This commit is contained in:
@@ -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)
|
||||
|
@@ -4,6 +4,8 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"time"
|
||||
|
||||
"git.icod.de/dalu/refdata/model"
|
||||
"github.com/globalsign/mgo"
|
||||
"github.com/globalsign/mgo/bson"
|
||||
@@ -54,6 +56,18 @@ type DataEnabledQuery struct {
|
||||
Query bool
|
||||
}
|
||||
|
||||
// refid
|
||||
type DataRefIdQuery struct {
|
||||
Query string
|
||||
}
|
||||
|
||||
// time
|
||||
type DataWhenQuery struct {
|
||||
Operation string
|
||||
From time.Time
|
||||
To time.Time
|
||||
}
|
||||
|
||||
type DataParams struct {
|
||||
Start int // list only
|
||||
Limit int // list only
|
||||
@@ -66,6 +80,7 @@ type DataParams struct {
|
||||
Age bool
|
||||
Price bool
|
||||
Enabled bool
|
||||
When bool
|
||||
|
||||
IdQuery DataIdQuery // get only
|
||||
NameQuery DataNameQuery
|
||||
@@ -74,6 +89,7 @@ type DataParams struct {
|
||||
AgeQuery DataAgeQuery
|
||||
PriceQuery DataPriceQuery
|
||||
EnabledQuery DataEnabledQuery
|
||||
WhenQuery DataWhenQuery
|
||||
}
|
||||
|
||||
type DataRepository struct {
|
||||
|
Reference in New Issue
Block a user