diff --git a/handlers/workflow.go b/handlers/workflow.go new file mode 100644 index 000000000..22253e878 --- /dev/null +++ b/handlers/workflow.go @@ -0,0 +1,30 @@ +package handlers + +import ( + "fmt" + "github.com/stakwork/sphinx-tribes/db" + "io" + "net/http" +) + +type workflowHandler struct { + db db.Database +} + +func NewWorkFlowHandler(database db.Database) *workflowHandler { + return &workflowHandler{ + db: database, + } +} + +func (oh *workflowHandler) HandleWorkflowRequest(w http.ResponseWriter, r *http.Request) { + + body, err := io.ReadAll(r.Body) + if err != nil { + fmt.Println("Error reading body:", err) + w.WriteHeader(http.StatusBadRequest) + return + } + fmt.Println("Request Body:", string(body)) + +} diff --git a/routes/index.go b/routes/index.go index 22090938c..fab5a9783 100644 --- a/routes/index.go +++ b/routes/index.go @@ -37,6 +37,7 @@ func NewRouter() *http.Server { r.Mount("/workspaces", WorkspaceRoutes()) r.Mount("/metrics", MetricsRoutes()) r.Mount("/features", FeatureRoutes()) + r.Mount("/workflows", WorkflowRoutes()) r.Group(func(r chi.Router) { r.Get("/tribe_by_feed", tribeHandlers.GetFirstTribeByFeed) diff --git a/routes/workflow_routes.go b/routes/workflow_routes.go new file mode 100644 index 000000000..420edf3e0 --- /dev/null +++ b/routes/workflow_routes.go @@ -0,0 +1,18 @@ +package routes + +import ( + "github.com/go-chi/chi" + "github.com/stakwork/sphinx-tribes/db" + "github.com/stakwork/sphinx-tribes/handlers" +) + +func WorkflowRoutes() chi.Router { + r := chi.NewRouter() + workflowHandlers := handlers.NewWorkFlowHandler(db.DB) + + r.Group(func(r chi.Router) { + r.Post("/request", workflowHandlers.HandleWorkflowRequest) + + }) + return r +} diff --git a/routes/workflow_routes_test.go b/routes/workflow_routes_test.go new file mode 100644 index 000000000..77d8fd529 --- /dev/null +++ b/routes/workflow_routes_test.go @@ -0,0 +1,22 @@ +package routes + +import ( + "net/http" + "net/http/httptest" + "testing" + + "github.com/go-chi/chi" + "github.com/stretchr/testify/assert" +) + +func TestWorkflowRoutes(t *testing.T) { + r := chi.NewRouter() + r.Mount("/workflows", WorkflowRoutes()) + + req := httptest.NewRequest("POST", "/workflows/request", nil) + w := httptest.NewRecorder() + + r.ServeHTTP(w, req) + + assert.NotEqual(t, http.StatusNotFound, w.Code) +}