-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
92d3fa2
commit 886f645
Showing
4 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |