Пример #1
0
//CompleteTaskFunc is used to show the complete tasks, handles "/completed/" url
func CompleteTaskFunc(w http.ResponseWriter, r *http.Request) {
	if r.Method == "GET" {
		id, err := strconv.Atoi(r.URL.Path[len("/complete/"):])
		if err != nil {
			log.Println(err)
		} else {
			err = db.CompleteTask(id)
			if err != nil {
				message = "Complete task failed"
			} else {
				message = "Task marked complete"
			}
			http.Redirect(w, r, "/", http.StatusFound)
		}
	} else {
		message = "Method not allowed"
		http.Redirect(w, r, "/", http.StatusFound)
	}
}
Пример #2
0
//CompleteTaskFunc is used to show the complete tasks, handles "/completed/" url
func CompleteTaskFunc(w http.ResponseWriter, r *http.Request) {
	if r.Method != "GET" {
		http.Redirect(w, r, "/", http.StatusBadRequest)
		return
	}

	redirectURL := utils.GetRedirectUrl(r.Referer())
	id, err := strconv.Atoi(r.URL.Path[len("/complete/"):])
	if err != nil {
		log.Println(err)
	} else {
		username := sessions.GetCurrentUserName(r)
		err = db.CompleteTask(username, id)
		if err != nil {
			message = "Complete task failed"
		} else {
			message = "Task marked complete"
		}
		http.Redirect(w, r, redirectURL, http.StatusFound)
	}

}