From 376906ae75bd10fb22acbab918350b9921b15da8 Mon Sep 17 00:00:00 2001 From: Suraj Date: Fri, 5 Feb 2016 23:39:09 +0530 Subject: [PATCH] category of task can be updated now --- db/tasks.go | 24 ++++++++++++++++++++++-- views/otherViews.go | 3 ++- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/db/tasks.go b/db/tasks.go index 76618b8..ad613da 100644 --- a/db/tasks.go +++ b/db/tasks.go @@ -182,9 +182,29 @@ func AddTask(title, content, category string, taskPriority int) error { return err } +//GetCategoryIdByName will return the category ID for the category, used in the edit task +//function where we need to be able to update the categoryID of the task +func GetCategoryIdByName(category string) int { + var categoryID int + getTasksql := "select id from category where name=?" + + rows := database.query(getTasksql, category) + defer rows.Close() + if rows.Next() { + err := rows.Scan(&categoryID) + if err != nil { + log.Println(err) + //send email to respective people + } + } + + return categoryID +} + //UpdateTask is used to update the tasks in the database -func UpdateTask(id int, title string, content string) error { - err := taskQuery("update task set title=?, content=? where id=?", title, content, id) +func UpdateTask(id int, title, content, category string) error { + categoryID := GetCategoryIdByName(category) + err := taskQuery("update task set title=?, content=?, cat_id=? where id=?", title, content, categoryID, id) return err } diff --git a/views/otherViews.go b/views/otherViews.go index ec5226b..0413838 100644 --- a/views/otherViews.go +++ b/views/otherViews.go @@ -93,9 +93,10 @@ func UpdateTaskFunc(w http.ResponseWriter, r *http.Request) { if err != nil { log.Println(err) } + category := r.Form.Get("category") title := r.Form.Get("title") content := r.Form.Get("content") - err = db.UpdateTask(id, title, content) + err = db.UpdateTask(id, title, content, category) if err != nil { message = "Error updating task" } else {