Open platform to collect and prioritize feedback
refactor: rename totalVotes and totalComments (#541)
Guilherme Oenninga815416392e4
diff --git a/app/handlers/apiv1/post_test.go b/app/handlers/apiv1/post_test.goindex d5f4dd5fb..487726e15 100644--- a/app/handlers/apiv1/post_test.go+++ b/app/handlers/apiv1/post_test.go@@ -26,7 +26,7 @@ func TestCreatePostHandler(t *testing.T) {Expect(code).Equals(http.StatusOK)Expect(err).IsNil()Expect(post.Title).Equals("My newest post :)")- Expect(post.TotalVotes).Equals(1)+ Expect(post.VotesCount).Equals(1)}func TestCreatePostHandler_WithoutTitle(t *testing.T) {@@ -252,8 +252,8 @@ func TestAddVoteHandler(t *testing.T) {second, _ = services.Posts.GetByNumber(2)Expect(code).Equals(http.StatusOK)- Expect(first.TotalVotes).Equals(0)- Expect(second.TotalVotes).Equals(1)+ Expect(first.VotesCount).Equals(0)+ Expect(second.VotesCount).Equals(1)}func TestAddVoteHandler_InvalidPost(t *testing.T) {@@ -288,7 +288,7 @@ func TestRemoveVoteHandler(t *testing.T) {post, _ = services.Posts.GetByNumber(post.Number)Expect(code).Equals(http.StatusOK)- Expect(post.TotalVotes).Equals(1)+ Expect(post.VotesCount).Equals(1)}func TestDeletePostHandler_Authorized(t *testing.T) {diff --git a/app/models/feedback.go b/app/models/feedback.goindex ec4d5d774..51f13f379 100644--- a/app/models/feedback.go+++ b/app/models/feedback.go@@ -15,8 +15,8 @@ type Post struct {CreatedAt time.Time `json:"createdAt"`User *User `json:"user"`HasVoted bool `json:"hasVoted"`- TotalVotes int `json:"totalVotes"`- TotalComments int `json:"totalComments"`+ VotesCount int `json:"votesCount"`+ CommentsCount int `json:"commentsCount"`Status PostStatus `json:"status"`Response *PostResponse `json:"response,omitempty"`Tags []string `json:"tags"`diff --git a/app/pkg/csv/csv.go b/app/pkg/csv/csv.goindex f9e00bd4c..7afbbb89b 100644--- a/app/pkg/csv/csv.go+++ b/app/pkg/csv/csv.go@@ -21,8 +21,8 @@ func FromPosts(posts []*models.Post) ([]byte, error) {"description","created_at","created_by",- "total_votes",- "total_comments",+ "votes_count",+ "comments_count","status","responded_by","responded_at",@@ -60,8 +60,8 @@ func FromPosts(posts []*models.Post) ([]byte, error) {post.Description,post.CreatedAt.Format(time.RFC3339),post.User.Name,- strconv.Itoa(post.TotalVotes),- strconv.Itoa(post.TotalComments),+ strconv.Itoa(post.VotesCount),+ strconv.Itoa(post.CommentsCount),post.Status.Name(),respondedBy,respondedAt,diff --git a/app/pkg/csv/csv_test.go b/app/pkg/csv/csv_test.goindex b8e2db64f..11d3b21d1 100644--- a/app/pkg/csv/csv_test.go+++ b/app/pkg/csv/csv_test.go@@ -59,8 +59,8 @@ var declinedPost = &models.Post{User: &models.User{Name: "Faceless",},- TotalVotes: 4,- TotalComments: 2,+ VotesCount: 4,+ CommentsCount: 2,Status: models.PostDeclined,Response: &models.PostResponse{Text: "Nothing we need to do",@@ -80,8 +80,8 @@ var openPost = &models.Post{User: &models.User{Name: "Someone else",},- TotalVotes: 4,- TotalComments: 2,+ VotesCount: 4,+ CommentsCount: 2,Status: models.PostOpen,}@@ -93,8 +93,8 @@ var duplicatePost = &models.Post{User: &models.User{Name: "Faceless",},- TotalVotes: 4,- TotalComments: 2,+ VotesCount: 4,+ CommentsCount: 2,Status: models.PostDuplicate,Response: &models.PostResponse{Text: "This has already been suggested",diff --git a/app/pkg/csv/testdata/empty.csv b/app/pkg/csv/testdata/empty.csvindex 908f59f34..e11b2d92c 100644--- a/app/pkg/csv/testdata/empty.csv+++ b/app/pkg/csv/testdata/empty.csv@@ -1 +1 @@-number,title,description,created_at,created_by,total_votes,total_comments,status,responded_by,responded_at,response,original_number,original_title,tags+number,title,description,created_at,created_by,votes_count,comments_count,status,responded_by,responded_at,response,original_number,original_title,tagsdiff --git a/app/pkg/csv/testdata/more-posts.csv b/app/pkg/csv/testdata/more-posts.csvindex 9a5404a47..b1d0f87e0 100755--- a/app/pkg/csv/testdata/more-posts.csv+++ b/app/pkg/csv/testdata/more-posts.csv@@ -1,4 +1,4 @@-number,title,description,created_at,created_by,total_votes,total_comments,status,responded_by,responded_at,response,original_number,original_title,tags+number,title,description,created_at,created_by,votes_count,comments_count,status,responded_by,responded_at,response,original_number,original_title,tags10,Go is fast,Very tiny description,2018-03-23T19:33:22Z,Faceless,4,2,declined,John Snow,2018-04-04T19:48:10Z,Nothing we need to do,,,"easy, ignored"15,Go is great,,2018-02-21T15:51:35Z,Someone else,4,2,open,,,,,,20,Go is easy,,2018-01-12T01:46:59Z,Faceless,4,2,duplicate,Arya Stark,2018-03-17T10:15:42Z,This has already been suggested,99,Go is very easy,"this-tag-has,comma"diff --git a/app/pkg/csv/testdata/one-post.csv b/app/pkg/csv/testdata/one-post.csvindex 4b1eb5379..194b018b1 100755--- a/app/pkg/csv/testdata/one-post.csv+++ b/app/pkg/csv/testdata/one-post.csv@@ -1,2 +1,2 @@-number,title,description,created_at,created_by,total_votes,total_comments,status,responded_by,responded_at,response,original_number,original_title,tags+number,title,description,created_at,created_by,votes_count,comments_count,status,responded_by,responded_at,response,original_number,original_title,tags10,Go is fast,Very tiny description,2018-03-23T19:33:22Z,Faceless,4,2,declined,John Snow,2018-04-04T19:48:10Z,Nothing we need to do,,,"easy, ignored"diff --git a/app/storage/inmemory/post.go b/app/storage/inmemory/post.goindex fb9f65cb2..ceca5c867 100644--- a/app/storage/inmemory/post.go+++ b/app/storage/inmemory/post.go@@ -156,7 +156,7 @@ func (s *PostStorage) UpdateComment(id int, content string) error {// AddVote adds user to post list of votesfunc (s *PostStorage) AddVote(post *models.Post, user *models.User) error {s.postsVotedBy[user.ID] = append(s.postsVotedBy[user.ID], post.ID)- post.TotalVotes = post.TotalVotes + 1+ post.VotesCount = post.VotesCount + 1return nil}@@ -168,7 +168,7 @@ func (s *PostStorage) RemoveVote(post *models.Post, user *models.User) error {break}}- post.TotalVotes = post.TotalVotes - 1+ post.VotesCount = post.VotesCount - 1return nil}diff --git a/app/storage/postgres/common.go b/app/storage/postgres/common.goindex a29b0136b..c29f29c5e 100644--- a/app/storage/postgres/common.go+++ b/app/storage/postgres/common.go@@ -33,9 +33,9 @@ func getFilterData(filter string) (string, []models.PostStatus, string) {condition = "AND has_voted = true"sort = "id"case "most-wanted":- sort = "votes"+ sort = "votes_count"case "most-discussed":- sort = "comments"+ sort = "comments_count"case "planned":sort = "response_date"statuses = []models.PostStatus{models.PostPlanned}@@ -60,7 +60,7 @@ func getFilterData(filter string) (string, []models.PostStatus, string) {case "trending":fallthroughdefault:- sort = "((COALESCE(recent_votes, 0)*5 + COALESCE(recent_comments, 0) *3)-1) / pow((EXTRACT(EPOCH FROM current_timestamp - created_at)/3600) + 2, 1.4)"+ sort = "((COALESCE(recent_votes_count, 0)*5 + COALESCE(recent_comments_count, 0) *3)-1) / pow((EXTRACT(EPOCH FROM current_timestamp - created_at)/3600) + 2, 1.4)"}return condition, statuses, sort}diff --git a/app/storage/postgres/post.go b/app/storage/postgres/post.goindex 81c1a9cbe..e4cd35971 100644--- a/app/storage/postgres/post.go+++ b/app/storage/postgres/post.go@@ -23,10 +23,10 @@ type dbPost struct {CreatedAt time.Time `db:"created_at"`User *dbUser `db:"user"`HasVoted bool `db:"has_voted"`- TotalVotes int `db:"votes"`- TotalComments int `db:"comments"`- RecentVotes int `db:"recent_votes"`- RecentComments int `db:"recent_comments"`+ VotesCount int `db:"votes_count"`+ CommentsCount int `db:"comments_count"`+ RecentVotes int `db:"recent_votes_count"`+ RecentComments int `db:"recent_comments_count"`Status int `db:"status"`Response sql.NullString `db:"response"`RespondedAt dbx.NullTime `db:"response_date"`@@ -47,8 +47,8 @@ func (i *dbPost) toModel() *models.Post {Description: i.Description,CreatedAt: i.CreatedAt,HasVoted: i.HasVoted,- TotalVotes: i.TotalVotes,- TotalComments: i.TotalComments,+ VotesCount: i.VotesCount,+ CommentsCount: i.CommentsCount,Status: models.PostStatus(i.Status),User: i.User.toModel(),Tags: i.Tags,@@ -156,10 +156,10 @@ var (p.slug,p.description,p.created_at,- COALESCE(agg_s.all, 0) as votes,- COALESCE(agg_c.all, 0) as comments,- COALESCE(agg_s.recent, 0) AS recent_votes,- COALESCE(agg_c.recent, 0) AS recent_comments,+ COALESCE(agg_s.all, 0) as votes_count,+ COALESCE(agg_c.all, 0) as comments_count,+ COALESCE(agg_s.recent, 0) AS recent_votes_count,+ COALESCE(agg_c.recent, 0) AS recent_comments_count,p.status,u.id AS user_id,u.name AS user_name,diff --git a/app/storage/postgres/post_test.go b/app/storage/postgres/post_test.goindex 6eda44daf..3fc611f5f 100644--- a/app/storage/postgres/post_test.go+++ b/app/storage/postgres/post_test.go@@ -30,7 +30,7 @@ func TestPostStorage_GetAll(t *testing.T) {Expect(dbPosts[0].Number).Equals(2)Expect(dbPosts[0].Description).Equals("no description")Expect(dbPosts[0].User.Name).Equals("Arya Stark")- Expect(dbPosts[0].TotalVotes).Equals(0)+ Expect(dbPosts[0].VotesCount).Equals(0)Expect(dbPosts[0].Status).Equals(models.PostCompleted)Expect(dbPosts[1].Title).Equals("add twitter integration")@@ -38,7 +38,7 @@ func TestPostStorage_GetAll(t *testing.T) {Expect(dbPosts[1].Number).Equals(1)Expect(dbPosts[1].Description).Equals("Would be great to see it integrated with twitter")Expect(dbPosts[1].User.Name).Equals("Jon Snow")- Expect(dbPosts[1].TotalVotes).Equals(0)+ Expect(dbPosts[1].VotesCount).Equals(0)Expect(dbPosts[1].Status).Equals(models.PostStarted)dbPosts, err = posts.Search("twitter", "trending", "10", []string{})@@ -65,7 +65,7 @@ func TestPostStorage_AddAndGet(t *testing.T) {Expect(dbPostByID.ID).Equals(post.ID)Expect(dbPostByID.Number).Equals(1)Expect(dbPostByID.HasVoted).IsFalse()- Expect(dbPostByID.TotalVotes).Equals(0)+ Expect(dbPostByID.VotesCount).Equals(0)Expect(dbPostByID.Status).Equals(models.PostOpen)Expect(dbPostByID.Title).Equals("My new post")Expect(dbPostByID.Description).Equals("with this description")@@ -79,7 +79,7 @@ func TestPostStorage_AddAndGet(t *testing.T) {Expect(dbPostBySlug.ID).Equals(post.ID)Expect(dbPostBySlug.Number).Equals(1)Expect(dbPostBySlug.HasVoted).IsFalse()- Expect(dbPostBySlug.TotalVotes).Equals(0)+ Expect(dbPostBySlug.VotesCount).Equals(0)Expect(dbPostBySlug.Status).Equals(models.PostOpen)Expect(dbPostBySlug.Title).Equals("My new post")Expect(dbPostBySlug.Description).Equals("with this description")@@ -222,7 +222,7 @@ func TestPostStorage_AddVote(t *testing.T) {dbPost, err := posts.GetByNumber(1)Expect(dbPost.HasVoted).IsFalse()- Expect(dbPost.TotalVotes).Equals(1)+ Expect(dbPost.VotesCount).Equals(1)err = posts.AddVote(post, jonSnow)Expect(err).IsNil()@@ -230,7 +230,7 @@ func TestPostStorage_AddVote(t *testing.T) {dbPost, err = posts.GetByNumber(1)Expect(err).IsNil()Expect(dbPost.HasVoted).IsTrue()- Expect(dbPost.TotalVotes).Equals(2)+ Expect(dbPost.VotesCount).Equals(2)}func TestPostStorage_AddVote_Twice(t *testing.T) {@@ -250,7 +250,7 @@ func TestPostStorage_AddVote_Twice(t *testing.T) {dbPost, err := posts.GetByNumber(1)Expect(err).IsNil()- Expect(dbPost.TotalVotes).Equals(1)+ Expect(dbPost.VotesCount).Equals(1)}func TestPostStorage_RemoveVote(t *testing.T) {@@ -270,7 +270,7 @@ func TestPostStorage_RemoveVote(t *testing.T) {dbPost, err := posts.GetByNumber(1)Expect(err).IsNil()- Expect(dbPost.TotalVotes).Equals(0)+ Expect(dbPost.VotesCount).Equals(0)}func TestPostStorage_RemoveVote_Twice(t *testing.T) {@@ -293,7 +293,7 @@ func TestPostStorage_RemoveVote_Twice(t *testing.T) {dbPost, err := posts.GetByNumber(1)Expect(err).IsNil()- Expect(dbPost.TotalVotes).Equals(0)+ Expect(dbPost.VotesCount).Equals(0)}func TestPostStorage_SetResponse(t *testing.T) {@@ -365,14 +365,14 @@ func TestPostStorage_SetResponse_AsDuplicate(t *testing.T) {posts.MarkAsDuplicate(post2, post1)post1, _ = posts.GetByID(post1.ID)- Expect(post1.TotalVotes).Equals(2)+ Expect(post1.VotesCount).Equals(2)Expect(post1.Status).Equals(models.PostOpen)Expect(post1.Response).IsNil()post2, _ = posts.GetByID(post2.ID)Expect(post2.Response.Text).Equals("")- Expect(post2.TotalVotes).Equals(1)+ Expect(post2.VotesCount).Equals(1)Expect(post2.Status).Equals(models.PostDuplicate)Expect(post2.Response.User.ID).Equals(1)Expect(post2.Response.Original.Number).Equals(post1.Number)@@ -413,7 +413,7 @@ func TestPostStorage_AddVote_ClosedPost(t *testing.T) {dbPost, err := posts.GetByNumber(post.Number)Expect(err).IsNil()- Expect(dbPost.TotalVotes).Equals(0)+ Expect(dbPost.VotesCount).Equals(0)}func TestPostStorage_RemoveVote_ClosedPost(t *testing.T) {@@ -429,7 +429,7 @@ func TestPostStorage_RemoveVote_ClosedPost(t *testing.T) {dbPost, err := posts.GetByNumber(post.Number)Expect(err).IsNil()- Expect(dbPost.TotalVotes).Equals(1)+ Expect(dbPost.VotesCount).Equals(1)}func TestPostStorage_ListVotedPosts(t *testing.T) {diff --git a/public/components/VoteCounter.spec.tsx b/public/components/VoteCounter.spec.tsxindex 73316d65e..b9cc4790d 100644--- a/public/components/VoteCounter.spec.tsx+++ b/public/components/VoteCounter.spec.tsx@@ -22,8 +22,8 @@ beforeEach(() => {},hasVoted: false,response: null,- totalVotes: 5,- totalComments: 2,+ votesCount: 5,+ commentsCount: 2,tags: []};});@@ -31,7 +31,7 @@ beforeEach(() => {describe("<VoteCounter />", () => {test("when hasVoted === true", () => {post.hasVoted = true;- post.totalVotes = 9;+ post.votesCount = 9;const wrapper = shallow(<VoteCounter post={post} />);const button = wrapper.find("button");expect(button.text()).toBe("9");@@ -41,7 +41,7 @@ describe("<VoteCounter />", () => {test("when hasVoted === false", () => {post.hasVoted = false;- post.totalVotes = 2;+ post.votesCount = 2;const wrapper = shallow(<VoteCounter post={post} />);const button = wrapper.find("button");expect(button.text()).toBe("2");diff --git a/public/components/VoteCounter.tsx b/public/components/VoteCounter.tsxindex ccd877251..f6008db9e 100644--- a/public/components/VoteCounter.tsx+++ b/public/components/VoteCounter.tsx@@ -11,7 +11,7 @@ interface VoteCounterProps {interface VoteCounterState {voted: boolean;- total: number;+ count: number;showSignIn: boolean;}@@ -20,7 +20,7 @@ export class VoteCounter extends React.Component<VoteCounterProps, VoteCounterStsuper(props);this.state = {voted: props.post.hasVoted,- total: props.post.totalVotes,+ count: props.post.votesCount,showSignIn: false};}@@ -37,7 +37,7 @@ export class VoteCounter extends React.Component<VoteCounterProps, VoteCounterStif (response.ok) {this.setState(state => ({voted: !state.voted,- total: state.total + (state.voted ? -1 : 1)+ count: state.count + (state.voted ? -1 : 1)}));}};@@ -54,14 +54,14 @@ export class VoteCounter extends React.Component<VoteCounterProps, VoteCounterStconst vote = (<button className={className} onClick={this.voteOrUndo}><i className="caret up icon" />- {this.state.total}+ {this.state.count}</button>);const disabled = (<button className={className}><i className="caret up icon" />- {this.state.total}+ {this.state.count}</button>);diff --git a/public/models/post.ts b/public/models/post.tsindex 06074fe37..88cfeda03 100644--- a/public/models/post.ts+++ b/public/models/post.ts@@ -11,8 +11,8 @@ export interface Post {user: User;hasVoted: boolean;response: PostResponse | null;- totalVotes: number;- totalComments: number;+ votesCount: number;+ commentsCount: number;tags: string[];}diff --git a/public/pages/Home/components/ListPosts.tsx b/public/pages/Home/components/ListPosts.tsxindex e831497c6..41abbd372 100644--- a/public/pages/Home/components/ListPosts.tsx+++ b/public/pages/Home/components/ListPosts.tsx@@ -24,9 +24,9 @@ const ListPostItem = (props: { post: Post; user?: CurrentUser; tags: Tag[] }) =><ListItem><VoteCounter post={props.post} /><div className="c-list-item-content">- {props.post.totalComments > 0 && (+ {props.post.commentsCount > 0 && (<div className="info right">- {props.post.totalComments} <i className="comments outline icon" />+ {props.post.commentsCount} <i className="comments outline icon" /></div>)}<a className="c-list-item-title" href={`/posts/${props.post.number}/${props.post.slug}`}>diff --git a/public/pages/ShowPost/components/PostSearch.tsx b/public/pages/ShowPost/components/PostSearch.tsxindex 99c28cf8b..29bb1155b 100644--- a/public/pages/ShowPost/components/PostSearch.tsx+++ b/public/pages/ShowPost/components/PostSearch.tsx@@ -57,7 +57,7 @@ export class PostSearch extends React.Component<PostSearchProps, PostSearchState<><span className="votes"><i className="caret up icon" />- {i.totalVotes}+ {i.votesCount}</span><span className={`status-label status-${status.value}`}>{status.title}</span>{i.title}