From 3c5e5460e80ba664cb351eef1de2f6731b7ec83f Mon Sep 17 00:00:00 2001 From: Suraj Patil Date: Sun, 15 May 2016 18:00:19 +0530 Subject: [PATCH] comments now show the username --- db/tasks.go | 4 ++-- templates/home.html | 2 +- types/types.go | 7 ++++--- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/db/tasks.go b/db/tasks.go index a0e5a44..5c45196 100644 --- a/db/tasks.go +++ b/db/tasks.go @@ -330,12 +330,12 @@ func GetComments(username string) (map[int][]types.Comment, error) { if err != nil { return commentMap, err } - stmt := "select c.id, c.taskID, c.content, c.created from comments c, task t where t.id=c.taskID and c.user_id=?;" + stmt := "select c.id, c.taskID, c.content, c.created, u.username from comments c, task t, user u where t.id=c.taskID and c.user_id=t.user_id and t.user_id=u.id and u.id=?" rows := database.query(stmt, userID) defer rows.Close() for rows.Next() { - err := rows.Scan(&comment.ID, &taskID, &comment.Content, &created) + err := rows.Scan(&comment.ID, &taskID, &comment.Content, &created, &comment.Username) if err != nil { return commentMap, err } diff --git a/templates/home.html b/templates/home.html index 8dc1d00..f587fcc 100644 --- a/templates/home.html +++ b/templates/home.html @@ -60,7 +60,7 @@ {{range $value.Comments}}
{{.Content}} - {{.Created}} + {{.Username}} {{.Created}}
{{end}} diff --git a/types/types.go b/types/types.go index 72d04c6..e4580a3 100644 --- a/types/types.go +++ b/types/types.go @@ -19,9 +19,10 @@ type Task struct { //Comment is the struct used to populate comments per tasks type Comment struct { - ID int - Content string - Created string + ID int + Content string + Created string + Username string } //Context is the struct passed to templates