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 {