Esempio n. 1
0
//DeleteTaskFunc is used to delete a task, trash = move to recycle bin, delete = permanent delete
func DeleteTaskFunc(w http.ResponseWriter, r *http.Request) {
	if r.Method == "GET" {
		id := r.URL.Path[len("/delete/"):]
		if id == "all" {
			err := db.DeleteAll()
			if err != nil {
				message = "Error deleting tasks"
				http.Redirect(w, r, "/", http.StatusInternalServerError)
			}
			http.Redirect(w, r, "/", http.StatusFound)
		} else {
			id, err := strconv.Atoi(id)
			if err != nil {
				log.Println(err)
				http.Redirect(w, r, "/", http.StatusBadRequest)
			} else {
				err = db.DeleteTask(id)
				if err != nil {
					message = "Error deleting task"
				} else {
					message = "Task deleted"
				}
				http.Redirect(w, r, "/deleted", http.StatusFound)
			}
		}
	} else {
		message = "Method not allowed"
		http.Redirect(w, r, "/", http.StatusFound)
	}
}
Esempio n. 2
0
//DeleteTaskFunc is used to delete a task, trash = move to recycle bin, delete = permanent delete
func DeleteTaskFunc(w http.ResponseWriter, r *http.Request) {
	username := sessions.GetCurrentUserName(r)
	if r.Method != "GET" {
		http.Redirect(w, r, "/", http.StatusBadRequest)
		return
	}

	id := r.URL.Path[len("/delete/"):]
	if id == "all" {
		err := db.DeleteAll(username)
		if err != nil {
			message = "Error deleting tasks"
			http.Redirect(w, r, "/", http.StatusInternalServerError)
		}
		http.Redirect(w, r, "/", http.StatusFound)
	} else {
		id, err := strconv.Atoi(id)
		if err != nil {
			log.Println(err)
			http.Redirect(w, r, "/", http.StatusBadRequest)
		} else {
			err = db.DeleteTask(username, id)
			if err != nil {
				message = "Error deleting task"
			} else {
				message = "Task deleted"
			}
			http.Redirect(w, r, "/deleted", http.StatusFound)
		}
	}

}