Skip to content

armgit / fider

Public Imported from GitHub
0

Open platform to collect and prioritize feedback

add more idea info

goenningb2f122154648
diff --git a/app/feedback/handler.go b/app/feedback/handler.go
index b545d6576..9f254d950 100644
--- a/app/feedback/handler.go
+++ b/app/feedback/handler.go
@@ -21,7 +21,11 @@ func Index(ideaService IdeaService) IndexHandlder {
func (h IndexHandlder) List() echo.HandlerFunc {
return func(c echo.Context) error {
tenant := c.Get("Tenant").(*identity.Tenant)
- ideas, _ := h.ideaService.GetAll(tenant.ID)
+ ideas, err := h.ideaService.GetAll(tenant.ID)
+ if err != nil {
+ return echo.NewHTTPError(http.StatusInternalServerError, err)
+ }
+
return c.Render(200, "index.html", echo.Map{
"Tenant": tenant,
"Ideas": ideas,
diff --git a/app/feedback/model.go b/app/feedback/model.go
index c9738becb..8e538bd23 100644
--- a/app/feedback/model.go
+++ b/app/feedback/model.go
@@ -2,12 +2,15 @@ package feedback
import (
"time"
+
+ "github.com/WeCanHearYou/wechy/app/identity"
)
//Idea represents an idea on a tenant board
type Idea struct {
- ID int64 `json:"id"`
- Title string `json:"title"`
- Description string `json:"description"`
- CreatedOn time.Time `json:"createdOn"`
+ ID int64 `json:"id"`
+ Title string `json:"title"`
+ Description string `json:"description"`
+ CreatedOn time.Time `json:"createdOn"`
+ User identity.User `json:"user"`
}
diff --git a/app/postgres/feedback.go b/app/postgres/feedback.go
index 8d48d490a..7d79f153f 100644
--- a/app/postgres/feedback.go
+++ b/app/postgres/feedback.go
@@ -15,7 +15,7 @@ type IdeaService struct {
// GetAll returns all tenant ideas
func (svc IdeaService) GetAll(tenantID int64) ([]*feedback.Idea, error) {
- rows, err := svc.DB.Query("SELECT id, title, description, created_on FROM ideas WHERE tenant_id = $1", tenantID)
+ rows, err := svc.DB.Query("SELECT i.id, i.title, i.description, i.created_on, u.id, u.name, u.email FROM ideas i LEFT JOIN users u ON u.id = i.user_id WHERE i.tenant_id = $1 ORDER BY i.created_on DESC", tenantID)
if err != nil {
return nil, err
}
@@ -23,7 +23,7 @@ func (svc IdeaService) GetAll(tenantID int64) ([]*feedback.Idea, error) {
var ideas []*feedback.Idea
for rows.Next() {
idea := &feedback.Idea{}
- rows.Scan(&idea.ID, &idea.Title, &idea.Description, &idea.CreatedOn)
+ rows.Scan(&idea.ID, &idea.Title, &idea.Description, &idea.CreatedOn, &idea.User.ID, &idea.User.Name, &idea.User.Email)
ideas = append(ideas, idea)
}
diff --git a/app/postgres/feedback_test.go b/app/postgres/feedback_test.go
index 0c22c2275..5147ae23a 100644
--- a/app/postgres/feedback_test.go
+++ b/app/postgres/feedback_test.go
@@ -8,6 +8,7 @@ import (
sqlmock "gopkg.in/DATA-DOG/go-sqlmock.v1"
"github.com/WeCanHearYou/wechy/app/feedback"
+ "github.com/WeCanHearYou/wechy/app/identity"
"github.com/WeCanHearYou/wechy/app/postgres"
. "github.com/onsi/gomega"
)
@@ -18,7 +19,7 @@ func TestIdeaService_GetAll_Error(t *testing.T) {
db, mock, _ := sqlmock.New()
defer db.Close()
- mock.ExpectQuery("SELECT id, title, description FROM ideas WHERE tenant_id = \\$1").WithArgs(2134).WillReturnError(driver.ErrBadConn)
+ mock.ExpectQuery("SELECT (.*) FROM ideas (.*) JOIN users").WithArgs(2134).WillReturnError(driver.ErrBadConn)
svc := &postgres.IdeaService{DB: db}
ideas, err := svc.GetAll(2134)
@@ -34,17 +35,36 @@ func TestIdeaService_GetAll(t *testing.T) {
defer db.Close()
now := time.Now()
- rows := sqlmock.NewRows([]string{"id", "title", "description", "created_on"})
- rows.AddRow(1, "Idea #1", "Description #1", now)
- rows.AddRow(2, "Idea #2", "Description #2", now)
-
- mock.ExpectQuery("SELECT id, title, description, created_on FROM ideas WHERE tenant_id = \\$1").WithArgs(2134).WillReturnRows(rows)
+ rows := sqlmock.NewRows([]string{"id", "title", "description", "created_on", "u_id", "u_name", "u_email"})
+ rows.AddRow(1, "Idea #1", "Description #1", now, 1, "Jon Snow", "[email protected]")
+ rows.AddRow(2, "Idea #2", "Description #2", now, 2, "Arya Start", "[email protected]")
+ mock.ExpectQuery("SELECT (.*) FROM ideas (.*) JOIN users").WithArgs(2134).WillReturnRows(rows)
svc := &postgres.IdeaService{DB: db}
ideas, err := svc.GetAll(2134)
- Expect(ideas).To(HaveLen(2))
- Expect(ideas[0]).To(Equal(&feedback.Idea{ID: 1, Title: "Idea #1", Description: "Description #1", CreatedOn: now}))
- Expect(ideas[1]).To(Equal(&feedback.Idea{ID: 2, Title: "Idea #2", Description: "Description #2", CreatedOn: now}))
Expect(err).To(BeNil())
+ Expect(ideas).To(HaveLen(2))
+ Expect(ideas[0]).To(Equal(&feedback.Idea{
+ ID: 1,
+ Title: "Idea #1",
+ Description: "Description #1",
+ CreatedOn: now,
+ User: identity.User{
+ ID: 1,
+ Name: "Jon Snow",
+ Email: "[email protected]",
+ },
+ }))
+ Expect(ideas[1]).To(Equal(&feedback.Idea{
+ ID: 2,
+ Title: "Idea #2",
+ Description: "Description #2",
+ CreatedOn: now,
+ User: identity.User{
+ ID: 2,
+ Name: "Arya Start",
+ Email: "[email protected]",
+ },
+ }))
}
diff --git a/public/components/Common.tsx b/public/components/Common.tsx
new file mode 100644
index 000000000..43d647220
--- /dev/null
+++ b/public/components/Common.tsx
@@ -0,0 +1,17 @@
+import * as React from "react";
+import md5 = require("md5");
+
+export const Gravatar = (props: {email?: string}) => {
+ const hash = props.email ? md5(props.email) : "";
+ return <img className="ui avatar image" src={ "https://www.gravatar.com/avatar/" + hash } />;
+};
+
+export const MultiLineText = (props: {text?: string}) => {
+ if (!props.text) {
+ return <p></p>;
+ }
+
+ return <div>{props.text.split("\n").map((item, i) =>
+ <span>{item}<br/></span>
+ )}</div>;
+};
diff --git a/public/components/Header.tsx b/public/components/Header.tsx
index 941bcb2a9..6d460f625 100644
--- a/public/components/Header.tsx
+++ b/public/components/Header.tsx
@@ -1,7 +1,7 @@
-import md5 = require("md5");
import * as React from "react";
import { Tenant } from "../models";
import { get, getCurrentUser } from "../storage";
+import { Gravatar } from "./Common";
import { SocialSignInButton } from "./SocialSignInButton";
export class Header extends React.Component<{}, {}> {
@@ -11,13 +11,12 @@ export class Header extends React.Component<{}, {}> {
const profile = user ?
<a className="item right signin">
- <img className="ui avatar image"
- src={ "https://www.gravatar.com/avatar/" + md5(user.email) } />
+ <Gravatar email={user.email} />
{ user.name }
<i className="dropdown icon"></i>
</a> :
<a className="item right signin">
- <img className="ui avatar image" src="https://www.gravatar.com/avatar/" />
+ <Gravatar />
Sign in
<i className="dropdown icon"></i>
</a>;
diff --git a/public/components/Root.tsx b/public/components/Root.tsx
index 3d629d6e4..ab23a1f39 100644
--- a/public/components/Root.tsx
+++ b/public/components/Root.tsx
@@ -2,6 +2,7 @@ import * as moment from "moment";
import * as React from "react";
import { Idea } from "../models";
import * as storage from "../storage";
+import { Gravatar, MultiLineText } from "./Common";
import { Footer } from "./Footer";
import { Header } from "./Header";
@@ -14,13 +15,15 @@ export class Root extends React.Component<{}, {}> {
const ideasList = ideas.map((x) =>
<div className="item" key={x.id}>
<div className="content">
- <a className="header">{ x.title }</a>
+ <div className="header">
+ <i className="idea icon"></i>{ x.title }
+ </div>
<div className="description">
- <p>{ x.title }</p>
+ <MultiLineText text={ x.description } />
</div>
<div className="extra">
- <i className="calendar icon"></i>
- shared { moment(x.createdOn).fromNow() }
+ <Gravatar email={x.user.email}/> <u>{x.user.name}</u>
+ shared <u title={x.createdOn}>{ moment(x.createdOn).fromNow() }</u>
</div>
</div>
</div>);
diff --git a/public/models.ts b/public/models.ts
index 39a487611..794b187fd 100644
--- a/public/models.ts
+++ b/public/models.ts
@@ -15,4 +15,5 @@ export interface Idea {
title: string;
description: string;
createdOn: string;
+ user: User;
}