update: dependencies

This commit is contained in:
Oarkflow
2024-11-14 19:15:27 +05:45
parent d68b68fe75
commit 15454d58f1
2 changed files with 42 additions and 38 deletions

View File

@@ -74,7 +74,7 @@ func (n *Operation) GetNodeType() string {
type Graph struct { type Graph struct {
Nodes map[string]Node Nodes map[string]Node
Edges map[string][]string Edges map[string][]string
tm *TaskManager Tm *TaskManager
} }
func NewGraph() *Graph { func NewGraph() *Graph {
@@ -83,22 +83,19 @@ func NewGraph() *Graph {
Edges: make(map[string][]string), Edges: make(map[string][]string),
} }
tm := NewTaskManager(g) tm := NewTaskManager(g)
g.tm = tm g.Tm = tm
return g return g
} }
func (g *Graph) Start() { func (g *Graph) Start() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { 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) { 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) { http.HandleFunc("/submit", func(w http.ResponseWriter, r *http.Request) {
submitHandler(w, r, g.tm) submitHandler(w, r, g.Tm)
})
http.HandleFunc("/verify", func(w http.ResponseWriter, r *http.Request) {
verifyHandler(w, r, g.tm)
}) })
fmt.Println("Server starting on :8080...") fmt.Println("Server starting on :8080...")
@@ -259,33 +256,3 @@ func startTaskHandler(w http.ResponseWriter, r *http.Request, tm *TaskManager) {
task := tm.StartTask() task := tm.StartTask()
http.Redirect(w, r, fmt.Sprintf("/render?taskID=%s", task.ID), http.StatusFound) 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))
}

View File

@@ -1,9 +1,12 @@
package main package main
import ( import (
"context"
"encoding/json" "encoding/json"
"fmt" "fmt"
"github.com/oarkflow/mq/dag/v2" "github.com/oarkflow/mq/dag/v2"
"log"
"net/http"
) )
func main() { func main() {
@@ -115,6 +118,10 @@ func main() {
graph.AddEdge("manualVerificationPage", "denyVerification") graph.AddEdge("manualVerificationPage", "denyVerification")
graph.AddEdge("verifyApproved", "approveCustomer") graph.AddEdge("verifyApproved", "approveCustomer")
graph.AddEdge("denyVerification", "verificationLinkPage") graph.AddEdge("denyVerification", "verificationLinkPage")
http.HandleFunc("/verify", func(w http.ResponseWriter, r *http.Request) {
verifyHandler(w, r, graph.Tm)
})
graph.Start() graph.Start()
} }
@@ -125,3 +132,33 @@ func isValidEmail(email string) bool {
func isValidPhone(phone string) bool { func isValidPhone(phone string) bool {
return phone != "" 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))
}