-
Notifications
You must be signed in to change notification settings - Fork 62
/
list_product_tags.go
48 lines (40 loc) · 1003 Bytes
/
list_product_tags.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package ecommerce
import (
"fmt"
"net/http"
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
)
func (ec *EcommerceController) ListProductTags() gin.HandlerFunc {
return func(c *gin.Context) {
projectTag := c.Param("project_tag")
project, err := ec.ProjectService.GetProjectByTag(projectTag)
if err != nil {
logrus.Error(err.Error())
c.JSON(http.StatusBadRequest, gin.H{
"message": err.Error(),
})
return
}
if project.Type != "ecommerce" {
c.JSON(http.StatusBadRequest, gin.H{
"message": "this project isn't an 'ecommerce' project",
})
return
}
listProductTagsQuery := fmt.Sprintf(`
SELECT DISTINCT unnest(tags) as tag
FROM products
WHERE status='published'
ORDER BY tag;`)
result, err := ec.DatabaseService.RunDatabaseQuery(projectTag, listProductTagsQuery)
if err != nil {
logrus.Error(err.Error())
c.JSON(http.StatusBadRequest, gin.H{
"message": err.Error(),
})
return
}
c.JSON(http.StatusOK, result)
}
}