allow fetching merps of all types now

This commit is contained in:
Jeffrey Paul 2019-11-08 04:55:54 -08:00
parent 037a23dd94
commit 62e7600a22
1 changed files with 12 additions and 8 deletions

20
merp.go
View File

@ -34,17 +34,21 @@ func getLatestMerps() gin.HandlerFunc {
h := func(c *gin.Context) { h := func(c *gin.Context) {
thing := c.Param("thing") thing := c.Param("thing")
if ThingRegex.MatchString(thing) == false { if thing != "" {
c.JSON(http.StatusPreconditionFailed, gin.H{ if ThingRegex.MatchString(thing) == false {
"this": "failed", c.JSON(http.StatusPreconditionFailed, gin.H{
"status": http.StatusPreconditionFailed, "this": "failed",
"because": "invalid thing format, try [a-zA-Z0-9-_]", "status": http.StatusPreconditionFailed,
}) "because": "invalid thing format, try [a-zA-Z0-9-_]",
return })
return
}
qs := orm.QueryTable("merp").Filter("thing", thing).OrderBy("-created").Limit(50)
} else {
qs := orm.QueryTable("merp").OrderBy("-created").Limit(50)
} }
var merps []*models.Merp var merps []*models.Merp
qs := orm.QueryTable("merp").Filter("thing", thing).OrderBy("-created").Limit(50)
qs.All(&merps) qs.All(&merps)
output := make([]map[string]interface{}, 0) output := make([]map[string]interface{}, 0)