about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/http.go30
1 files changed, 26 insertions, 4 deletions
diff --git a/src/http.go b/src/http.go
index 4df6944..079ecba 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("/editSelect", editSelectGetHandler).Methods("GET")
 	r.HandleFunc("/api/getChallenges", getChallenges).Methods("GET")
 
 	return http.Server{
@@ -119,14 +120,35 @@ func viewGetHandler(w http.ResponseWriter, r *http.Request) {
 	t.ExecuteTemplate(w, "view", challenges)
 }
 
+func editSelectGetHandler(w http.ResponseWriter, r *http.Request) {
+	// get all challenges from the db
+	challs := dbGetAllChallenges()
+
+	// define a challenges struct storing the challenges.
+	// This struct can be used in a template
+	challenges := Challenges{}
+
+	for _, chal := range challs {
+		challenges.Challenge = append(challenges.Challenge, chal)
+	}
+
+	// define a new template to render the challenges in
+	t := template.New("")
+	t, err := t.ParseFiles("./hosted/edit.html")
+	if err != nil {
+		log.Println(err)
+		return
+	}
+
+	// execure the template using the challenges struct
+	t.ExecuteTemplate(w, "edit", challenges)
+}
+
 func editGetHandler(w http.ResponseWriter, r *http.Request) {
 	var uuid string
 
 	if r.URL.Query()["uuid"] == nil {
-		log.Println("no uuid given")
-
-		// redirect the user to the view page for selecting what challenge to edit
-		viewGetHandler(w, r)
+		log.Println("editnoparam")
 		return
 	}
 	uuid = r.URL.Query()["uuid"][0]