From 15454d58f1ec286e60d1d31bbc7a910d164ab4ba Mon Sep 17 00:00:00 2001 From: Oarkflow Date: Thu, 14 Nov 2024 19:15:27 +0545 Subject: [PATCH] update: dependencies --- dag/v2/v2.go | 43 +++++-------------------------------------- examples/html.go | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 38 deletions(-) diff --git a/dag/v2/v2.go b/dag/v2/v2.go index c766434..e92123c 100644 --- a/dag/v2/v2.go +++ b/dag/v2/v2.go @@ -74,7 +74,7 @@ func (n *Operation) GetNodeType() string { type Graph struct { Nodes map[string]Node Edges map[string][]string - tm *TaskManager + Tm *TaskManager } func NewGraph() *Graph { @@ -83,22 +83,19 @@ func NewGraph() *Graph { Edges: make(map[string][]string), } tm := NewTaskManager(g) - g.tm = tm + g.Tm = tm return g } func (g *Graph) Start() { http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { - startTaskHandler(w, r, g.tm) + startTaskHandler(w, r, g.Tm) }) http.HandleFunc("/render", func(w http.ResponseWriter, r *http.Request) { - renderHandler(w, r, g.tm) + renderHandler(w, r, g.Tm) }) http.HandleFunc("/submit", func(w http.ResponseWriter, r *http.Request) { - submitHandler(w, r, g.tm) - }) - http.HandleFunc("/verify", func(w http.ResponseWriter, r *http.Request) { - verifyHandler(w, r, g.tm) + submitHandler(w, r, g.Tm) }) fmt.Println("Server starting on :8080...") @@ -259,33 +256,3 @@ func startTaskHandler(w http.ResponseWriter, r *http.Request, tm *TaskManager) { task := tm.StartTask() http.Redirect(w, r, fmt.Sprintf("/render?taskID=%s", task.ID), http.StatusFound) } - -func verifyHandler(w http.ResponseWriter, r *http.Request, tm *TaskManager) { - taskID := r.URL.Query().Get("taskID") - if taskID == "" { - http.Error(w, "Missing taskID", http.StatusBadRequest) - return - } - task, exists := tm.GetTask(taskID) - if !exists { - http.Error(w, "Task not found", http.StatusNotFound) - return - } - data := map[string]any{ - "email_verified": "true", - } - bt, _ := json.Marshal(data) - task.Payload = bt - log.Printf("Email for taskID %s successfully verified.", task.ID) - nextNode, exists := tm.Graph.Nodes["dashboard"] - if !exists { - http.Error(w, "Dashboard Operation not found", http.StatusInternalServerError) - return - } - result := nextNode.ProcessTask(context.Background(), task) - if result.Error != nil { - http.Error(w, result.Error.Error(), http.StatusInternalServerError) - return - } - fmt.Fprintf(w, string(result.Payload)) -} diff --git a/examples/html.go b/examples/html.go index 1634a28..949dd40 100644 --- a/examples/html.go +++ b/examples/html.go @@ -1,9 +1,12 @@ package main import ( + "context" "encoding/json" "fmt" "github.com/oarkflow/mq/dag/v2" + "log" + "net/http" ) func main() { @@ -115,6 +118,10 @@ func main() { graph.AddEdge("manualVerificationPage", "denyVerification") graph.AddEdge("verifyApproved", "approveCustomer") graph.AddEdge("denyVerification", "verificationLinkPage") + + http.HandleFunc("/verify", func(w http.ResponseWriter, r *http.Request) { + verifyHandler(w, r, graph.Tm) + }) graph.Start() } @@ -125,3 +132,33 @@ func isValidEmail(email string) bool { func isValidPhone(phone string) bool { return phone != "" } + +func verifyHandler(w http.ResponseWriter, r *http.Request, tm *v2.TaskManager) { + taskID := r.URL.Query().Get("taskID") + if taskID == "" { + http.Error(w, "Missing taskID", http.StatusBadRequest) + return + } + task, exists := tm.GetTask(taskID) + if !exists { + http.Error(w, "Task not found", http.StatusNotFound) + return + } + data := map[string]any{ + "email_verified": "true", + } + bt, _ := json.Marshal(data) + task.Payload = bt + log.Printf("Email for taskID %s successfully verified.", task.ID) + nextNode, exists := tm.Graph.Nodes["dashboard"] + if !exists { + http.Error(w, "Dashboard Operation not found", http.StatusInternalServerError) + return + } + result := nextNode.ProcessTask(context.Background(), task) + if result.Error != nil { + http.Error(w, result.Error.Error(), http.StatusInternalServerError) + return + } + fmt.Fprintf(w, string(result.Payload)) +}