-
Notifications
You must be signed in to change notification settings - Fork 62
/
get_email_pipeline.go
58 lines (50 loc) · 1.46 KB
/
get_email_pipeline.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
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) GetEmailPipeline() gin.HandlerFunc {
return func(c *gin.Context) {
projectTag := c.Param("project_tag")
pipelineName := c.Param("pipeline_name")
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
}
if utils.ContainsString(DefaultPipelineNames, pipelineName) {
c.JSON(http.StatusBadRequest, gin.H{
"message": "this pipeline isn't an email scheduling pipeline",
})
return
}
pipeline, err := ec.PipelineService.GetPipelineByName(accountId, pipelineName, project.Name)
if err != nil {
logrus.Error(err.Error())
c.JSON(http.StatusBadRequest, gin.H{
"message": err.Error(),
})
return
}
metadata := pipeline.PipelineDetailes.Manifest.Triggers["scheduler"].Credentials["ecommerce_metadata"].(map[string]interface{})
emailPipeline := map[string]interface{}{
"name": pipelineName,
"is_active": pipeline.IsActive,
"endpoint": pipeline.Endpoint,
"metadata": metadata,
}
c.JSON(http.StatusOK, emailPipeline)
}
}