about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEmile <hanemile@protonmail.com>2019-10-20 02:26:04 +0200
committerEmile <hanemile@protonmail.com>2019-10-20 02:26:04 +0200
commitbefddbcbcabe60a04db59d1f64f962c85ec7f2dc (patch)
treec132c5d189e02ada552087767d59a29160a2e36e
parent62bd43c35728a7062ab850708090d1259102e776 (diff)
delete function
-rw-r--r--src/http.go19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/http.go b/src/http.go
index 079ecba..443b6a3 100644
--- a/src/http.go
+++ b/src/http.go
@@ -32,6 +32,7 @@ func setupHTTPServer() http.Server {
 	r.HandleFunc("/view", viewGetHandler).Methods("GET")
 	r.HandleFunc("/edit", editGetHandler).Methods("GET")
 	r.HandleFunc("/edit", editPostHandler).Methods("POST")
+	r.HandleFunc("/delete", deleteHandler)
 	r.HandleFunc("/editSelect", editSelectGetHandler).Methods("GET")
 	r.HandleFunc("/api/getChallenges", getChallenges).Methods("GET")
 
@@ -219,6 +220,24 @@ func editPostHandler(w http.ResponseWriter, r *http.Request) {
 	http.Redirect(w, r, "/edit", http.StatusSeeOther)
 }
 
+func deleteHandler(w http.ResponseWriter, r *http.Request) {
+	err := r.ParseForm()
+	if err != nil {
+		log.Println("deleteHandler could not parse the form")
+		log.Println(err)
+	}
+
+	if r.URL.Query()["uuid"] == nil {
+		log.Println("delete: no uuid given")
+		return
+	}
+	uuid := r.URL.Query()["uuid"][0]
+	log.Printf("Deleteing challenge with uuid %s\n", uuid)
+
+	dbDeleteChallengeByUUID(uuid)
+	http.Redirect(w, r, "/editSelect", http.StatusSeeOther)
+}
+
 // Helper function to host files off of "hosted/" directory
 func readFileToResponse(w http.ResponseWriter, path string) {
 	requestedFile := strings.Replace(path, "..", "", -1)