-
Notifications
You must be signed in to change notification settings - Fork 62
/
get_email_pipelines.go
68 lines (61 loc) · 1.73 KB
/
get_email_pipelines.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package ecommerce
import (
"net/http"
"github.com/dotenx/dotenx/ao-api/pkg/utils"
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
)
func (ec *EcommerceController) GetEmailPipelines() gin.HandlerFunc {
return func(c *gin.Context) {
projectTag := c.Param("project_tag")
accountId, _ := utils.GetAccountId(c)
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
}
pipelines, err := ec.PipelineService.ListProjectPipelines(accountId, project.Name)
if err != nil {
logrus.Error(err.Error())
c.JSON(http.StatusInternalServerError, gin.H{
"message": err.Error(),
})
return
}
emailPipelines := make([]map[string]interface{}, 0)
for _, p := range pipelines {
if p.ProjectName == project.Name {
if utils.ContainsString(DefaultPipelineNames, p.Name) {
continue
}
pipeline, err := ec.PipelineService.GetPipelineByName(accountId, p.Name, project.Name)
if err != nil {
logrus.Error(err.Error())
c.JSON(http.StatusInternalServerError, gin.H{
"message": err.Error(),
})
return
}
metadata := pipeline.PipelineDetailes.Manifest.Triggers["scheduler"].Credentials["ecommerce_metadata"].(map[string]interface{})
emailPipelines = append(emailPipelines, map[string]interface{}{
"name": p.Name,
"is_active": p.IsActive,
"endpoint": p.Endpoint,
"metadata": metadata,
})
}
}
c.JSON(http.StatusOK, gin.H{
"pipelines": emailPipelines,
})
}
}