comments now show the username

This commit is contained in:
Suraj Patil 2016-05-15 18:00:19 +05:30
parent a6d9a109c0
commit 3c5e5460e8
3 changed files with 7 additions and 6 deletions

View File

@ -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
}

View File

@ -60,7 +60,7 @@
{{range $value.Comments}}
<div class="comment">
<span>{{.Content}}</span>
<span class="timestamp">{{.Created}}</span>
<span class="timestamp">{{.Username}} {{.Created}}</span>
<a href="/del-comment/{{.ID}}"><span class="glyphicon glyphicon-trash timestamp"></span></a>
</div>
{{end}}

View File

@ -22,6 +22,7 @@ type Comment struct {
ID int
Content string
Created string
Username string
}
//Context is the struct passed to templates