Skip to content

armgit / fider

Public Imported from GitHub
0

Open platform to collect and prioritize feedback

use number instead of id

goenning052ba543fe45
diff --git a/app/handlers/feedback.go b/app/handlers/feedback.go
index 3e0bfb5c4..59cc021f3 100644
--- a/app/handlers/feedback.go
+++ b/app/handlers/feedback.go
@@ -61,9 +61,7 @@ func (h AllHandlers) PostIdea() web.HandlerFunc {
return c.Failure(err)
}
- return c.JSON(200, echo.Map{
- "idea": idea,
- })
+ return c.JSON(200, idea)
}
}
@@ -115,18 +113,24 @@ func (h AllHandlers) PostComment() web.HandlerFunc {
})
}
- ideaID, err := c.ParamAsInt("id")
+ ideaNumber, err := c.ParamAsInt("number")
if err != nil {
return c.Failure(err)
}
- id, err := h.ideas.AddComment(c.User().ID, ideaID, input.Content)
+ idea, err := h.ideas.GetByNumber(c.Tenant().ID, ideaNumber)
if err != nil {
+ if err == app.ErrNotFound {
+ return c.NotFound()
+ }
return c.Failure(err)
}
- return c.JSON(200, echo.Map{
- "comment_id": id,
- })
+ _, err = h.ideas.AddComment(c.User().ID, idea.ID, input.Content)
+ if err != nil {
+ return c.Failure(err)
+ }
+
+ return c.JSON(200, echo.Map{})
}
}
diff --git a/app/handlers/feedback_test.go b/app/handlers/feedback_test.go
index a89730d7b..573c413c9 100644
--- a/app/handlers/feedback_test.go
+++ b/app/handlers/feedback_test.go
@@ -53,7 +53,7 @@ func TestDetailsHandler_NotFound(t *testing.T) {
Expect(code).To(Equal(404))
}
-func TestDetailsHandler_AddIdea(t *testing.T) {
+func TestPostIdeaHandler(t *testing.T) {
RegisterTestingT(t)
ideas := &inmemory.IdeaStorage{}
@@ -70,7 +70,7 @@ func TestDetailsHandler_AddIdea(t *testing.T) {
Expect(idea.TotalSupporters).To(Equal(1))
}
-func TestDetailsHandler_AddIdea_WithoutTitle(t *testing.T) {
+func TestPostIdeaHandler_WithoutTitle(t *testing.T) {
RegisterTestingT(t)
ideas := &inmemory.IdeaStorage{}
@@ -85,14 +85,15 @@ func TestDetailsHandler_AddIdea_WithoutTitle(t *testing.T) {
Expect(err).NotTo(BeNil())
}
-func TestDetailsHandler_AddComment(t *testing.T) {
+func TestPostCommentHandler(t *testing.T) {
RegisterTestingT(t)
ideas := &inmemory.IdeaStorage{}
+ ideas.Save(1, 1, "Title", "Description")
server := mock.NewServer()
server.Context.SetTenant(&models.Tenant{ID: 1, Name: "Any Tenant"})
server.Context.SetUser(&models.User{ID: 1, Name: "Jon"})
- server.Context.SetParamNames("id")
+ server.Context.SetParamNames("number")
server.Context.SetParamValues("1")
handler := handlers.Handlers(ideas).PostComment()
code, _ := server.ExecutePost(handler, `{ "content": "This is a comment!" }`)
@@ -100,17 +101,35 @@ func TestDetailsHandler_AddComment(t *testing.T) {
Expect(code).To(Equal(200))
}
-func TestDetailsHandler_AddComment_WithoutContent(t *testing.T) {
+func TestPostCommentHandler_WithoutContent(t *testing.T) {
RegisterTestingT(t)
ideas := &inmemory.IdeaStorage{}
server := mock.NewServer()
server.Context.SetTenant(&models.Tenant{ID: 1, Name: "Any Tenant"})
server.Context.SetUser(&models.User{ID: 1, Name: "Jon"})
- server.Context.SetParamNames("id")
+ server.Context.SetParamNames("number")
server.Context.SetParamValues("1")
handler := handlers.Handlers(ideas).PostComment()
code, _ := server.ExecutePost(handler, `{ "content": "" }`)
Expect(code).To(Equal(400))
}
+
+/*
+func TestAddSupporterHandler(t *testing.T) {
+ RegisterTestingT(t)
+
+ ideas := &inmemory.IdeaStorage{}
+ ideas.Save(1, 1, "The Idea #1", "The Description #1")
+ ideas.Save(1, 1, "The Idea #2", "The Description #2")
+ server := mock.NewServer()
+ server.Context.SetTenant(&models.Tenant{ID: 1, Name: "Any Tenant"})
+ server.Context.SetUser(&models.User{ID: 1, Name: "Jon"})
+ server.Context.SetParamNames("number")
+ server.Context.SetParamValues("2")
+ code, _ := server.Execute(handlers.Handlers(ideas).AddSupporter())
+
+ Expect(code).To(Equal(200))
+}
+*/
diff --git a/app/pkg/web/engine.go b/app/pkg/web/engine.go
index 8f4c6c5e8..667bc25b1 100644
--- a/app/pkg/web/engine.go
+++ b/app/pkg/web/engine.go
@@ -4,6 +4,8 @@ import (
"net/http"
"strings"
+ "fmt"
+
"github.com/WeCanHearYou/wechy/app/pkg/env"
"github.com/labstack/echo"
"github.com/labstack/echo/middleware"
@@ -63,7 +65,7 @@ func (g *Group) Post(path string, handler HandlerFunc) {
func errorHandler(e error, c echo.Context) {
if strings.Contains(e.Error(), "code=404") {
- c.Logger().Debug(e)
+ c.Logger().Debug(fmt.Sprintf("%s [%s] %s", e, c.Request().Method, c.Request().URL.String()))
c.Render(http.StatusNotFound, "404.html", echo.Map{})
} else {
c.Logger().Error(e)
diff --git a/public/components/comment_input.tsx b/public/components/comment_input.tsx
index 91e233bf1..bf7a3518b 100644
--- a/public/components/comment_input.tsx
+++ b/public/components/comment_input.tsx
@@ -32,7 +32,7 @@ export class CommentInput extends React.Component<CommentInputProps, CommentInpu
});
try {
- await axios.post(`/api/ideas/${this.props.idea.id}/comments`, {
+ await axios.post(`/api/ideas/${this.props.idea.number}/comments`, {
content: this.state.content
});
diff --git a/router.go b/router.go
index d5b2448a5..7e67cd7f1 100644
--- a/router.go
+++ b/router.go
@@ -51,7 +51,7 @@ func GetMainEngine(ctx *WeCHYServices) *web.Engine {
private.Use(middlewares.IsAuthenticated())
private.Post("/api/ideas", handlers.Handlers(ctx.Idea).PostIdea())
- private.Post("/api/ideas/:id/comments", handlers.Handlers(ctx.Idea).PostComment())
+ private.Post("/api/ideas/:number/comments", handlers.Handlers(ctx.Idea).PostComment())
}
auth := r.Group("/oauth")