diff --git a/db/db.go b/db/db.go index 32ddb26..b232118 100644 --- a/db/db.go +++ b/db/db.go @@ -60,8 +60,8 @@ func GetTasks(status string) []types.Task { return task } -//GetTaskById function gets the tasks from the ID passed to the function -func GetTaskById(id int) types.Task { +//GetTaskByID function gets the tasks from the ID passed to the function +func GetTaskByID(id int) types.Task { var task types.Task var TaskID int var TaskTitle string @@ -223,24 +223,25 @@ func UpdateTask(id int, title string, content string) error { //SearchTask is used to return the search results depending on the query func SearchTask(query string) []types.Task { - stmt := "select id, title, content from task where title like '%" + query + "%' or content like '%" + query + "%'" + stmt := "select id, title, content, created_date from task where title like '%" + query + "%' or content like '%" + query + "%'" var task []types.Task var TaskID int var TaskTitle string var TaskContent string + var TaskCreated time.Time rows, err := database.Query(stmt, query, query) if err != nil { fmt.Println(err) } for rows.Next() { - err := rows.Scan(&TaskID, &TaskTitle, &TaskContent) + err := rows.Scan(&TaskID, &TaskTitle, &TaskContent, &TaskCreated) if err != nil { fmt.Println(err) } TaskTitle = strings.Replace(TaskTitle, query, ""+query+"", -1) TaskContent = strings.Replace(TaskContent, query, ""+query+"", -1) - a := types.Task{Id: TaskID, Title: TaskTitle, Content: TaskContent} + a := types.Task{Id: TaskID, Title: TaskTitle, Content: TaskContent, Created: TaskCreated.Format(time.UnixDate)[0:20]} task = append(task, a) } return task diff --git a/public/templates/search.html b/public/templates/search.html index 71f2b08..ce7b36b 100644 --- a/public/templates/search.html +++ b/public/templates/search.html @@ -1,8 +1,4 @@ {{template "_head.html"}} - - - -
{{ if .}} {{range .}}
@@ -10,27 +6,25 @@

{{.Content}}

-
diff --git a/views/views.go b/views/views.go index 6f4ad21..c8770df 100644 --- a/views/views.go +++ b/views/views.go @@ -105,7 +105,7 @@ func EditTaskFunc(w http.ResponseWriter, r *http.Request) { if err != nil { fmt.Println(err) } else { - task := db.GetTaskById(id) + task := db.GetTaskByID(id) editTemplate.Execute(w, task) } }