category of task can be updated now
This commit is contained in:
parent
2a49110f7f
commit
376906ae75
24
db/tasks.go
24
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
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue