params consolidation, fixed numeric params

This commit is contained in:
Darko Luketic
2018-03-28 04:24:06 +02:00
parent 80abb6a862
commit 6761f8d666
3 changed files with 99 additions and 134 deletions

View File

@@ -28,7 +28,7 @@ func (h *Handler) FindData(cx *gin.Context) {
}
func (h *Handler) ListData(cx *gin.Context) {
p := new(repo.DataListParams)
p := new(repo.DataParams)
startQuery := cx.Query("start")
if startQuery != "" {
@@ -56,6 +56,7 @@ func (h *Handler) ListData(cx *gin.Context) {
location := cx.Query("location")
age := cx.Query("age")
price := cx.Query("price")
enabled := cx.Query("enabled")
// string
if name == "1" {
@@ -120,6 +121,18 @@ func (h *Handler) ListData(cx *gin.Context) {
p.PriceQuery.To = to
}
if enabled == "1" {
p.Enabled = true
p.EnabledQuery = repo.DataEnabledQuery{}
if cx.Query("enabled.query") == "true" {
p.EnabledQuery.Query = true
} else if cx.Query("enabled.query") == "false" {
p.EnabledQuery.Query = false
} else {
p.Enabled = false
}
}
m, e := h.dataRepo.List(p)
if e != nil {
cx.AbortWithError(500, e)
@@ -129,7 +142,7 @@ func (h *Handler) ListData(cx *gin.Context) {
}
func (h *Handler) GetData(cx *gin.Context) {
p := new(repo.DataGetParams)
p := new(repo.DataParams)
id := cx.Query("id")
name := cx.Query("name")
@@ -137,6 +150,7 @@ func (h *Handler) GetData(cx *gin.Context) {
location := cx.Query("location")
age := cx.Query("age")
price := cx.Query("price")
enabled := cx.Query("enabled")
// id
if id == "1" {
@@ -210,6 +224,18 @@ func (h *Handler) GetData(cx *gin.Context) {
p.PriceQuery.To = to
}
if enabled == "1" {
p.Enabled = true
p.EnabledQuery = repo.DataEnabledQuery{}
if cx.Query("enabled.query") == "true" {
p.EnabledQuery.Query = true
} else if cx.Query("enabled.query") == "false" {
p.EnabledQuery.Query = false
} else {
p.Enabled = false
}
}
m, e := h.dataRepo.Get(p)
if e != nil {
cx.AbortWithError(500, e)