forked from OrgGo/Tasks
handled incorrect req methods
This commit is contained in:
parent
8eea6f51f5
commit
a5f50060aa
|
@ -71,7 +71,7 @@ func SearchTaskFunc(w http.ResponseWriter, r *http.Request) {
|
||||||
context := db.SearchTask(query)
|
context := db.SearchTask(query)
|
||||||
searchTemplate.Execute(w, context)
|
searchTemplate.Execute(w, context)
|
||||||
} else {
|
} else {
|
||||||
|
http.Redirect(w, r, "/", http.StatusFound)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -88,6 +88,8 @@ func AddTaskFunc(w http.ResponseWriter, r *http.Request) {
|
||||||
} else {
|
} else {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
http.Redirect(w, r, "/", http.StatusFound)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,11 +98,14 @@ func ShowCompleteTasksFunc(w http.ResponseWriter, r *http.Request) {
|
||||||
if r.Method == "GET" {
|
if r.Method == "GET" {
|
||||||
context := db.GetTasks("complete") //false when you want finished notes
|
context := db.GetTasks("complete") //false when you want finished notes
|
||||||
completedTemplate.Execute(w, context)
|
completedTemplate.Execute(w, context)
|
||||||
|
} else {
|
||||||
|
http.Redirect(w, r, "/", http.StatusFound)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//EditTaskFunc is used to edit tasks, handles "/edit/" URL
|
//EditTaskFunc is used to edit tasks, handles "/edit/" URL
|
||||||
func EditTaskFunc(w http.ResponseWriter, r *http.Request) {
|
func EditTaskFunc(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if r.Method == "GET" {
|
||||||
id, err := strconv.Atoi(r.URL.Path[len("/edit/"):])
|
id, err := strconv.Atoi(r.URL.Path[len("/edit/"):])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
|
@ -108,6 +113,9 @@ func EditTaskFunc(w http.ResponseWriter, r *http.Request) {
|
||||||
task := db.GetTaskByID(id)
|
task := db.GetTaskByID(id)
|
||||||
editTemplate.Execute(w, task)
|
editTemplate.Execute(w, task)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
http.Redirect(w, r, "/", http.StatusFound)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//CompleteTaskFunc is used to show the complete tasks, handles "/completed/" url
|
//CompleteTaskFunc is used to show the complete tasks, handles "/completed/" url
|
||||||
|
@ -124,6 +132,8 @@ func CompleteTaskFunc(w http.ResponseWriter, r *http.Request) {
|
||||||
fmt.Println("redirecting to home")
|
fmt.Println("redirecting to home")
|
||||||
http.Redirect(w, r, "/", http.StatusFound)
|
http.Redirect(w, r, "/", http.StatusFound)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
http.Redirect(w, r, "/", http.StatusFound)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,11 +153,14 @@ func DeleteTaskFunc(w http.ResponseWriter, r *http.Request) {
|
||||||
http.Redirect(w, r, "/deleted/", http.StatusFound)
|
http.Redirect(w, r, "/deleted/", http.StatusFound)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
http.Redirect(w, r, "/", http.StatusFound)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//TrashTaskFunc is used to populate the "/trash/" URL
|
//TrashTaskFunc is used to populate the "/trash/" URL
|
||||||
func TrashTaskFunc(w http.ResponseWriter, r *http.Request) {
|
func TrashTaskFunc(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if r.Method == "GET" {
|
||||||
id, err := strconv.Atoi(r.URL.Path[len("/trash/"):])
|
id, err := strconv.Atoi(r.URL.Path[len("/trash/"):])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
|
@ -155,10 +168,14 @@ func TrashTaskFunc(w http.ResponseWriter, r *http.Request) {
|
||||||
db.TrashTask(id)
|
db.TrashTask(id)
|
||||||
http.Redirect(w, r, "/", http.StatusFound)
|
http.Redirect(w, r, "/", http.StatusFound)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
http.Redirect(w, r, "/", http.StatusFound)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//RestoreTaskFunc is used to restore task from trash, handles "/restore/" URL
|
//RestoreTaskFunc is used to restore task from trash, handles "/restore/" URL
|
||||||
func RestoreTaskFunc(w http.ResponseWriter, r *http.Request) {
|
func RestoreTaskFunc(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if r.Method == "GET" {
|
||||||
id, err := strconv.Atoi(r.URL.Path[len("/restore/"):])
|
id, err := strconv.Atoi(r.URL.Path[len("/restore/"):])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
|
@ -166,10 +183,14 @@ func RestoreTaskFunc(w http.ResponseWriter, r *http.Request) {
|
||||||
db.RestoreTask(id)
|
db.RestoreTask(id)
|
||||||
http.Redirect(w, r, "/deleted/", http.StatusFound)
|
http.Redirect(w, r, "/deleted/", http.StatusFound)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
http.Redirect(w, r, "/", http.StatusFound)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//UpdateTaskFunc is used to update a task, handes "/update/" URL
|
//UpdateTaskFunc is used to update a task, handes "/update/" URL
|
||||||
func UpdateTaskFunc(w http.ResponseWriter, r *http.Request) {
|
func UpdateTaskFunc(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if r.Method == "POST"{
|
||||||
r.ParseForm()
|
r.ParseForm()
|
||||||
id, err := strconv.Atoi(r.Form.Get("id"))
|
id, err := strconv.Atoi(r.Form.Get("id"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -179,6 +200,9 @@ func UpdateTaskFunc(w http.ResponseWriter, r *http.Request) {
|
||||||
content := r.Form.Get("content")
|
content := r.Form.Get("content")
|
||||||
db.UpdateTask(id, title, content)
|
db.UpdateTask(id, title, content)
|
||||||
http.Redirect(w, r, "/", http.StatusFound)
|
http.Redirect(w, r, "/", http.StatusFound)
|
||||||
|
} else {
|
||||||
|
http.Redirect(w, r, "/", http.StatusFound)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//ServeStaticFunc is used to serve static files
|
//ServeStaticFunc is used to serve static files
|
||||||
|
|
Loading…
Reference in New Issue