Open platform to collect and prioritize feedback
add status column and default value
goenningf498d58b50ee
diff --git a/app/models/feedback.go b/app/models/feedback.goindex 44e80a0f8..96e39520d 100644--- a/app/models/feedback.go+++ b/app/models/feedback.go@@ -6,15 +6,30 @@ import (//Idea represents an idea on a tenant boardtype Idea struct {- ID int `json:"id" db:"id"`- Number int `json:"number" db:"number"`- Title string `json:"title" db:"title"`- Description string `json:"description" db:"description"`- CreatedOn time.Time `json:"createdOn" db:"created_on"`- User *User `json:"user" db:"user"`- TotalSupporters int `json:"totalSupporters" db:"supporters"`+ ID int `json:"id" db:"id"`+ Number int `json:"number" db:"number"`+ Title string `json:"title" db:"title"`+ Description string `json:"description" db:"description"`+ CreatedOn time.Time `json:"createdOn" db:"created_on"`+ User *User `json:"user" db:"user"`+ TotalSupporters int `json:"totalSupporters" db:"supporters"`+ Status IdeaStatus `json:"status" db:"status"`}+//IdeaStatus represents the status of an idea+type IdeaStatus int++var (+ //IdeaNew is the default status+ IdeaNew = IdeaStatus(0)+ //IdeaStarted is used when the idea has been accepted and work is in progress+ IdeaStarted = IdeaStatus(1)+ //IdeaCompleted is used when the idea has been accepted and already implemented+ IdeaCompleted = IdeaStatus(2)+ //IdeaDeclined is used when organizers decide to decline an idea+ IdeaDeclined = IdeaStatus(3)+)+//Comment represents an user comment on an ideatype Comment struct {ID int `json:"id" db:"id"`diff --git a/app/storage/postgres/idea.go b/app/storage/postgres/idea.goindex 3a863cf95..92ea325b8 100644--- a/app/storage/postgres/idea.go+++ b/app/storage/postgres/idea.go@@ -22,6 +22,7 @@ var (i.description,i.created_on,i.supporters,+ i.status,u.id AS user_id,u.name AS user_name,u.email AS user_email@@ -106,8 +107,8 @@ func (s *IdeaStorage) Save(tenantID, userID int, title, description string) (*moidea.Title = titleidea.Description = description- row := tx.QueryRow(`INSERT INTO ideas (title, number, description, tenant_id, user_id, created_on, supporters)- VALUES ($1, (SELECT COALESCE(MAX(number), 0) + 1 FROM ideas i WHERE i.tenant_id = $3), $2, $3, $4, $5, 0)+ row := tx.QueryRow(`INSERT INTO ideas (title, number, description, tenant_id, user_id, created_on, supporters, status)+ VALUES ($1, (SELECT COALESCE(MAX(number), 0) + 1 FROM ideas i WHERE i.tenant_id = $3), $2, $3, $4, $5, 0, 0)RETURNING id`, title, description, tenantID, userID, time.Now())if err = row.Scan(&idea.ID); err != nil {tx.Rollback()diff --git a/app/storage/postgres/idea_test.go b/app/storage/postgres/idea_test.goindex 1e8aef8ad..db35c22a9 100644--- a/app/storage/postgres/idea_test.go+++ b/app/storage/postgres/idea_test.go@@ -5,6 +5,7 @@ import ("time""github.com/WeCanHearYou/wechy/app"+ "github.com/WeCanHearYou/wechy/app/models""github.com/WeCanHearYou/wechy/app/pkg/dbx""github.com/WeCanHearYou/wechy/app/storage/postgres". "github.com/onsi/gomega"@@ -17,8 +18,8 @@ func TestIdeaStorage_GetAll(t *testing.T) {now := time.Now()- db.Execute("INSERT INTO ideas (title, number, description, created_on, tenant_id, user_id, supporters) VALUES ('Idea #1', 1, 'Description #1', $1, 300, 300, 0)", now)- db.Execute("INSERT INTO ideas (title, number, description, created_on, tenant_id, user_id, supporters) VALUES ('Idea #2', 2, 'Description #2', $1, 300, 301, 5)", now)+ db.Execute("INSERT INTO ideas (title, number, description, created_on, tenant_id, user_id, supporters, status) VALUES ('Idea #1', 1, 'Description #1', $1, 300, 300, 0, 1)", now)+ db.Execute("INSERT INTO ideas (title, number, description, created_on, tenant_id, user_id, supporters, status) VALUES ('Idea #2', 2, 'Description #2', $1, 300, 301, 5, 2)", now)ideas := &postgres.IdeaStorage{DB: db}dbIdeas, err := ideas.GetAll(300)@@ -31,12 +32,14 @@ func TestIdeaStorage_GetAll(t *testing.T) {Expect(dbIdeas[0].Description).To(Equal("Description #1"))Expect(dbIdeas[0].User.Name).To(Equal("Jon Snow"))Expect(dbIdeas[0].TotalSupporters).To(Equal(0))+ Expect(dbIdeas[0].Status).To(Equal(models.IdeaStarted))Expect(dbIdeas[1].Title).To(Equal("Idea #2"))Expect(dbIdeas[1].Number).To(Equal(2))Expect(dbIdeas[1].Description).To(Equal("Description #2"))Expect(dbIdeas[1].User.Name).To(Equal("Arya Stark"))Expect(dbIdeas[1].TotalSupporters).To(Equal(5))+ Expect(dbIdeas[1].Status).To(Equal(models.IdeaCompleted))}func TestIdeaStorage_SaveAndGet(t *testing.T) {@@ -58,6 +61,7 @@ func TestIdeaStorage_SaveAndGet(t *testing.T) {Expect(dbIdea.ID).To(Equal(1))Expect(dbIdea.Number).To(Equal(1))Expect(dbIdea.TotalSupporters).To(Equal(0))+ Expect(dbIdea.Status).To(Equal(models.IdeaNew))Expect(dbIdea.Title).To(Equal("My new idea"))Expect(dbIdea.Description).To(Equal("with this description"))Expect(dbIdea.User.ID).To(Equal(1))diff --git a/migrations/201705132054_add_idea_status.up.sql b/migrations/201705132054_add_idea_status.up.sqlnew file mode 100644index 000000000..39d9a6ace--- /dev/null+++ b/migrations/201705132054_add_idea_status.up.sql@@ -0,0 +1,5 @@+ALTER TABLE ideas ADD status INT;++UPDATE ideas SET status = 0;++ALTER TABLE ideas ALTER COLUMN status SET NOT NULL;\ No newline at end of file