Пример #1
0
//RestoreTaskFunc is used to restore task from trash, handles "/restore/" URL
func RestoreTaskFunc(w http.ResponseWriter, r *http.Request) {
	if r.Method == "GET" {
		id, err := strconv.Atoi(r.URL.Path[len("/restore/"):])
		if err != nil {
			fmt.Println(err)
		} else {
			err = db.RestoreTask(id)
			if err != nil {
				message = "Restore failed"
			} else {
				message = "Task restored"
			}
			http.Redirect(w, r, "/deleted/", http.StatusFound)
		}
	} else {
		message = "Method not allowed"
		http.Redirect(w, r, "/", http.StatusFound)
	}
}
Пример #2
0
//RestoreTaskFunc is used to restore task from trash, handles "/restore/" URL
func RestoreTaskFunc(w http.ResponseWriter, r *http.Request) {
	if r.Method != "GET" {
		http.Redirect(w, r, "/", http.StatusBadRequest)
		return
	}

	id, err := strconv.Atoi(r.URL.Path[len("/restore/"):])
	if err != nil {
		log.Println(err)
		http.Redirect(w, r, "/deleted", http.StatusBadRequest)
	} else {
		username := sessions.GetCurrentUserName(r)
		err = db.RestoreTask(username, id)
		if err != nil {
			message = "Restore failed"
		} else {
			message = "Task restored"
		}
		http.Redirect(w, r, "/deleted/", http.StatusFound)
	}

}