コード例 #1
0
ファイル: views.go プロジェクト: gotej/Tasks
//RestoreFromCompleteFunc restores the task from complete to pending
func RestoreFromCompleteFunc(w http.ResponseWriter, r *http.Request) {
	if r.Method == "GET" {
		id, err := strconv.Atoi(r.URL.Path[len("/incomplete/"):])
		if err != nil {
			log.Println(err)
		} else {
			err = db.RestoreTaskFromComplete(id)
			if err != nil {
				message = "Restore failed"
			} else {
				message = "Task restored"
			}
			http.Redirect(w, r, "/pending/", http.StatusFound)
		}
	} else {
		message = "Method not allowed"
		http.Redirect(w, r, "/", http.StatusFound)
	}
}
コード例 #2
0
ファイル: deleteViews.go プロジェクト: thewhitetulip/Tasks
//RestoreFromCompleteFunc restores the task from complete to pending
func RestoreFromCompleteFunc(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("/incomplete/"):])
	if err != nil {
		log.Println(err)
		http.Redirect(w, r, "/completed", http.StatusBadRequest)
	} else {
		username := sessions.GetCurrentUserName(r)
		err = db.RestoreTaskFromComplete(username, id)
		if err != nil {
			message = "Restore failed"
		} else {
			message = "Task restored"
		}
		http.Redirect(w, r, "/completed", http.StatusFound)
	}

}