Open platform to collect and prioritize feedback
use int
goenningf09e3edd2cf0
diff --git a/app/context.go b/app/context.goindex 051557952..8cfe94cf8 100644--- a/app/context.go+++ b/app/context.go@@ -52,13 +52,13 @@ func (ctx *Context) SetClaims(claims *WechyClaims) {ctx.Set(claimsContextKey, claims)}-//ParamAsInt64 returns parameter as int64-func (ctx *Context) ParamAsInt64(name string) (int64, error) {+//ParamAsInt returns parameter as int+func (ctx *Context) ParamAsInt(name string) (int, error) {val, err := strconv.Atoi(ctx.Param(name))if err != nil {return 0, err}- return int64(val), nil+ return int(val), nil}//HandlerFunc represents an HTTP handlerdiff --git a/app/feedback/handler.go b/app/feedback/handler.goindex 0ec8800ec..209a75aed 100644--- a/app/feedback/handler.go+++ b/app/feedback/handler.go@@ -57,7 +57,7 @@ func (h IndexHandlder) Post() app.HandlerFunc {func (h IndexHandlder) Details() app.HandlerFunc {return func(c app.Context) error {tenant := c.Tenant()- ideaID, _ := c.ParamAsInt64("id")+ ideaID, _ := c.ParamAsInt("id")idea, _ := h.ideaService.GetByID(tenant.ID, ideaID)comments, _ := h.ideaService.GetCommentsByIdeaID(tenant.ID, idea.ID)@@ -80,7 +80,7 @@ func (h IndexHandlder) PostComment() app.HandlerFunc {return c.Failure(err)}- ideaID, _ := c.ParamAsInt64("id")+ ideaID, _ := c.ParamAsInt("id")id, err := h.ideaService.AddComment(c.Claims().UserID, ideaID, input.Content)if err != nil {diff --git a/app/feedback/handler_test.go b/app/feedback/handler_test.goindex 81c25b4cc..138ab246e 100644--- a/app/feedback/handler_test.go+++ b/app/feedback/handler_test.go@@ -11,23 +11,23 @@ import (type mockIdeaService struct{}-func (svc mockIdeaService) GetByID(tenantID, ideaID int64) (*feedback.Idea, error) {+func (svc mockIdeaService) GetByID(tenantID, ideaID int) (*feedback.Idea, error) {return new(feedback.Idea), nil}-func (svc mockIdeaService) GetAll(tenantID int64) ([]*feedback.Idea, error) {+func (svc mockIdeaService) GetAll(tenantID int) ([]*feedback.Idea, error) {return make([]*feedback.Idea, 0), nil}-func (svc mockIdeaService) GetCommentsByIdeaID(tenantID, ideaID int64) ([]*feedback.Comment, error) {+func (svc mockIdeaService) GetCommentsByIdeaID(tenantID, ideaID int) ([]*feedback.Comment, error) {return make([]*feedback.Comment, 0), nil}-func (svc mockIdeaService) Save(tenantID, userID int64, title, description string) (*feedback.Idea, error) {+func (svc mockIdeaService) Save(tenantID, userID int, title, description string) (*feedback.Idea, error) {return nil, nil}-func (svc mockIdeaService) AddComment(userID, ideaID int64, content string) (int64, error) {+func (svc mockIdeaService) AddComment(userID, ideaID int, content string) (int, error) {return 0, nil}diff --git a/app/feedback/model.go b/app/feedback/model.goindex ed6d42b8d..5fb818996 100644--- a/app/feedback/model.go+++ b/app/feedback/model.go@@ -8,7 +8,7 @@ import (//Idea represents an idea on a tenant boardtype Idea struct {- ID int64 `json:"id"`+ ID int `json:"id"`Title string `json:"title"`Description string `json:"description"`CreatedOn time.Time `json:"createdOn"`@@ -17,7 +17,7 @@ type Idea struct {//Comment represents an user comment on an ideatype Comment struct {- ID int64 `json:"id"`+ ID int `json:"id"`Content string `json:"content"`CreatedOn time.Time `json:"createdOn"`User app.User `json:"user"`diff --git a/app/feedback/service.go b/app/feedback/service.goindex 2deda8a54..ccde16457 100644--- a/app/feedback/service.go+++ b/app/feedback/service.go@@ -2,9 +2,9 @@ package feedback// IdeaService contains read and write operations for ideastype IdeaService interface {- GetByID(tenantID, ideaID int64) (*Idea, error)- GetCommentsByIdeaID(tenantID, ideaID int64) ([]*Comment, error)- GetAll(tenantID int64) ([]*Idea, error)- Save(tenantID, userID int64, title, description string) (*Idea, error)- AddComment(userID, ideaID int64, content string) (int64, error)+ GetByID(tenantID, ideaID int) (*Idea, error)+ GetCommentsByIdeaID(tenantID, ideaID int) ([]*Comment, error)+ GetAll(tenantID int) ([]*Idea, error)+ Save(tenantID, userID int, title, description string) (*Idea, error)+ AddComment(userID, ideaID int, content string) (int, error)}diff --git a/app/model.go b/app/model.goindex e795c0075..06be5ab1b 100644--- a/app/model.go+++ b/app/model.go@@ -4,14 +4,14 @@ import jwt "github.com/dgrijalva/jwt-go"//Tenant represents a tenanttype Tenant struct {- ID int64 `json:"id"`+ ID int `json:"id"`Name string `json:"name"`Domain string `json:"domain"`}//User represents an user inside our applicationtype User struct {- ID int64 `json:"id"`+ ID int `json:"id"`Name string `json:"name"`Email string `json:"email"`Providers []*UserProvider `json:"providers"`@@ -25,7 +25,7 @@ type UserProvider struct {//WechyClaims represents what goes into JWT tokenstype WechyClaims struct {- UserID int64 `json:"user/id"`+ UserID int `json:"user/id"`UserName string `json:"user/name"`UserEmail string `json:"user/email"`jwt.StandardClaimsdiff --git a/app/postgres/feedback.go b/app/postgres/feedback.goindex 5963472d9..36d7f81c4 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) {+func (svc IdeaService) GetAll(tenantID int) ([]*feedback.Idea, error) {rows, err := svc.DB.Query(`SELECT i.id, i.title, i.description, i.created_on, u.id, u.name, u.emailFROM ideas iINNER JOIN users u@@ -37,7 +37,7 @@ func (svc IdeaService) GetAll(tenantID int64) ([]*feedback.Idea, error) {}// GetByID returns idea by given id-func (svc IdeaService) GetByID(tenantID, ideaID int64) (*feedback.Idea, error) {+func (svc IdeaService) GetByID(tenantID, ideaID int) (*feedback.Idea, error) {rows, err := svc.DB.Query(`SELECT i.id, i.title, i.description, i.created_on, u.id, u.name, u.emailFROM ideas iINNER JOIN users u@@ -58,7 +58,7 @@ func (svc IdeaService) GetByID(tenantID, ideaID int64) (*feedback.Idea, error) {}// GetCommentsByIdeaID returns all coments from given idea-func (svc IdeaService) GetCommentsByIdeaID(tenantID, ideaID int64) ([]*feedback.Comment, error) {+func (svc IdeaService) GetCommentsByIdeaID(tenantID, ideaID int) ([]*feedback.Comment, error) {rows, err := svc.DB.Query(`SELECT c.id, c.content, c.created_on, u.id, u.name, u.emailFROM comments cINNER JOIN ideas i@@ -83,7 +83,7 @@ func (svc IdeaService) GetCommentsByIdeaID(tenantID, ideaID int64) ([]*feedback.}// Save a new idea in the database-func (svc IdeaService) Save(tenantID, userID int64, title, description string) (*feedback.Idea, error) {+func (svc IdeaService) Save(tenantID, userID int, title, description string) (*feedback.Idea, error) {tx, err := svc.DB.Begin()if err != nil {return nil, err@@ -102,13 +102,13 @@ func (svc IdeaService) Save(tenantID, userID int64, title, description string) (}// AddComment places a new comment on an idea-func (svc IdeaService) AddComment(userID, ideaID int64, content string) (int64, error) {+func (svc IdeaService) AddComment(userID, ideaID int, content string) (int, error) {tx, err := svc.DB.Begin()if err != nil {return 0, err}- var id int64+ var id intif err = tx.QueryRow("INSERT INTO comments (idea_id, content, user_id, created_on) VALUES ($1, $2, $3, $4) RETURNING id", ideaID, content, userID, time.Now()).Scan(&id); err != nil {tx.Rollback()return 0, errdiff --git a/app/postgres/identity_test.go b/app/postgres/identity_test.goindex ad9a2ec2f..0872ce918 100644--- a/app/postgres/identity_test.go+++ b/app/postgres/identity_test.go@@ -32,7 +32,7 @@ func TestUserService_GetByEmail(t *testing.T) {user, err := svc.GetByEmail("[email protected]")Expect(err).To(BeNil())- Expect(user.ID).To(Equal(int64(1)))+ Expect(user.ID).To(Equal(int(1)))Expect(user.Name).To(Equal("Jon Snow"))Expect(user.Email).To(Equal("[email protected]"))}@@ -56,7 +56,7 @@ func TestUserService_Register(t *testing.T) {err := svc.Register(user)Expect(err).To(BeNil())- Expect(user.ID).To(Equal(int64(1)))+ Expect(user.ID).To(Equal(int(1)))Expect(user.Name).To(Equal("Jon Snow"))Expect(user.Email).To(Equal("[email protected]"))}@@ -84,7 +84,7 @@ func TestUserService_Register_MultipleProviders(t *testing.T) {err := svc.Register(user)Expect(err).To(BeNil())- Expect(user.ID).To(Equal(int64(1)))+ Expect(user.ID).To(Equal(int(1)))Expect(user.Name).To(Equal("Jon Snow"))Expect(user.Email).To(Equal("[email protected]"))}@@ -111,7 +111,7 @@ func TestTenantService_GetByDomain_Subdomain(t *testing.T) {svc := &postgres.TenantService{DB: db}tenant, err := svc.GetByDomain("mydomain")- Expect(tenant.ID).To(Equal(int64(1)))+ Expect(tenant.ID).To(Equal(int(1)))Expect(tenant.Name).To(Equal("My Domain Inc."))Expect(tenant.Domain).To(Equal("mydomain.test.canhearyou.com"))Expect(err).To(BeNil())@@ -127,7 +127,7 @@ func TestTenantService_GetByDomain_FullDomain(t *testing.T) {svc := &postgres.TenantService{DB: db}tenant, err := svc.GetByDomain("mydomain.anydomain.com")- Expect(tenant.ID).To(Equal(int64(1)))+ Expect(tenant.ID).To(Equal(int(1)))Expect(tenant.Name).To(Equal("My Domain Inc."))Expect(tenant.Domain).To(Equal("mydomain.test.canhearyou.com"))Expect(err).To(BeNil())