예제 #1
0
//SearchTaskFunc is used to handle the /search/ url, handles the search function
func SearchTaskFunc(w http.ResponseWriter, r *http.Request) {
	if r.Method == "POST" {
		r.ParseForm()
		query := r.Form.Get("query")
		context := db.SearchTask(query)
		searchTemplate.Execute(w, context)
	} else {
		message = "Method not allowed"
		http.Redirect(w, r, "/", http.StatusFound)
	}
}
예제 #2
0
//SearchTaskFunc is used to handle the /search/ url, handles the search function
func SearchTaskFunc(w http.ResponseWriter, r *http.Request) {
	if r.Method != "POST" {
		http.Redirect(w, r, "/", http.StatusBadRequest)
		return
	}
	r.ParseForm()
	query := r.Form.Get("query")

	username := sessions.GetCurrentUserName(r)
	context, err := db.SearchTask(username, query)
	if err != nil {
		log.Println("error fetching search results")
	}

	categories := db.GetCategories(username)
	context.Categories = categories

	searchTemplate.Execute(w, context)

}