From a6687225b8bb22c017dfa0eb9de9ce36c30a95db Mon Sep 17 00:00:00 2001 From: Jeffrey Paul Date: Fri, 8 Nov 2019 05:01:57 -0800 Subject: [PATCH] fixed bug --- merp.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/merp.go b/merp.go index f7c54d2..5b619c0 100644 --- a/merp.go +++ b/merp.go @@ -5,6 +5,7 @@ import "net/http" import "regexp" import "time" +import "github.com/astaxie/beego/orm" import "github.com/gin-gonic/gin" import "github.com/google/uuid" import "github.com/rs/zerolog/log" @@ -30,10 +31,12 @@ func decodeJSON(in []byte) interface{} { func getLatestMerps() gin.HandlerFunc { ThingRegex := thingRegex() - orm := models.GetOrmObject() + o := models.GetOrmObject() h := func(c *gin.Context) { + thing := c.Param("thing") + if thing != "" { if ThingRegex.MatchString(thing) == false { c.JSON(http.StatusPreconditionFailed, gin.H{ @@ -43,9 +46,13 @@ func getLatestMerps() gin.HandlerFunc { }) return } - qs := orm.QueryTable("merp").Filter("thing", thing).OrderBy("-created").Limit(50) + } + + var qs orm.QuerySeter + if thing == "" { + qs = o.QueryTable("merp").OrderBy("-created").Limit(50) } else { - qs := orm.QueryTable("merp").OrderBy("-created").Limit(50) + qs = o.QueryTable("merp").Filter("thing", thing).OrderBy("-created").Limit(50) } var merps []*models.Merp