Merge pull request #38 from tukataka/master

Fix query for getting task from database.
This commit is contained in:
Suraj Patil 2019-03-12 08:26:42 +05:30 committed by GitHub
commit 6088493ff5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 2 deletions

View File

@ -167,9 +167,9 @@ func GetTaskByID(username string, id int) (types.Context, error) {
var tasks []types.Task
var task types.Task
getTaskSQL := "select t.id, t.title, t.content, t.priority, t.hide, c.name from task t join user u left outer join category c where c.id = t.cat_id and t.user_id=u.id and t.id=? and u.username=? union select t.id, t.title, t.content, t.priority, t.hide, 'UNCATEGORIZED' from task t join user u where t.user_id=u.id and t.cat_id=0 ;"
getTaskSQL := "select t.id, t.title, t.content, t.priority, t.hide, c.name from task t join user u left outer join category c where c.id = t.cat_id and t.user_id=u.id and t.id=? and u.username=? union select t.id, t.title, t.content, t.priority, t.hide, 'UNCATEGORIZED' from task t join user u where t.user_id=u.id and t.cat_id=0 and t.id=? and u.username=?;"
rows := database.query(getTaskSQL, id, username)
rows := database.query(getTaskSQL, id, username, id, username)
defer rows.Close()
if rows.Next() {
err := rows.Scan(&task.Id, &task.Title, &task.Content, &task.Priority, &task.IsHidden, &task.Category)