Skip to content

Commit

Permalink
feat: bug fixed the getTrigger endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
CaelanHill committed Sep 27, 2024
1 parent ef1013b commit ffc3be7
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion api/handlers/workflow/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ func (w OrchestratorReal) GetTriggers() (string, error) {
logger := utilities.NewLogger().LogWithCaller()

// Send the GET request to the orchestrator
resp, err := http.Get("http://localhost:8090/triggers")
resp, err := http.Get("http://orchestrator:8090/triggers")
if err != nil {
logger.Error("get error: ", err)
return "", fmt.Errorf("internal server error")
Expand Down
10 changes: 7 additions & 3 deletions api/handlers/workflow/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -579,23 +579,27 @@ func (w Workflow) ResetActiveWorkflow(c *gin.Context) {
func (w Workflow) GetTriggers(c *gin.Context) {
logger := utilities.NewLogger().LogWithCaller()

// Fetch the triggers string from the orchestrator
triggers, err := w.OrchestratorEntity.GetTriggers()
if err != nil {
logger.Error(err)
c.JSON(http.StatusInternalServerError, models.Response{Error: "Internal Server Error"})
return
}

// Unmarshal the JSON string into the TriggerResponse struct
var response models.TriggerResponse
err = json.Unmarshal([]byte(triggers), &response)
if err != nil {
logger.Error(err)
c.JSON(http.StatusInternalServerError, models.Response{Error: "Internal Server Error"})
logger.Error("Failed to parse triggers JSON:", err)
c.JSON(http.StatusInternalServerError, models.Response{Error: "Failed to parse triggers JSON"})
return
}

// Return the structured response
c.JSON(http.StatusOK, models.Response{Data: response})

}




2 changes: 1 addition & 1 deletion api/models/responseModels.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,5 +180,5 @@ func (d *DurationWrapper) UnmarshalJSON(b []byte) error {


type TriggerResponse struct {
Trigger []string `json:"trigger"`
Trigger []string `json:"triggers"`
}
2 changes: 1 addition & 1 deletion orchestrator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func main() {
router.POST("/event", handlers.TransitionStateMachine)

// Add triggers endpoint
router.POST("/triggers", handlers.GetTriggers)
router.GET("/triggers", handlers.GetTriggers)

router.Run(":8090")

Expand Down

0 comments on commit ffc3be7

Please sign in to comment.