about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-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)