Skip to content

Commit

Permalink
add workflow request route
Browse files Browse the repository at this point in the history
  • Loading branch information
MahtabBukhari committed Nov 14, 2024
1 parent 92d3fa2 commit 886f645
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 0 deletions.
30 changes: 30 additions & 0 deletions handlers/workflow.go
Original file line number Diff line number Diff line change
@@ -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))

}
1 change: 1 addition & 0 deletions routes/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 18 additions & 0 deletions routes/workflow_routes.go
Original file line number Diff line number Diff line change
@@ -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
}
22 changes: 22 additions & 0 deletions routes/workflow_routes_test.go
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit 886f645

Please sign in to comment.