about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorEmile <hanemile@protonmail.com>2019-10-20 01:32:39 +0200
committerEmile <hanemile@protonmail.com>2019-10-20 01:32:39 +0200
commit9bd8dcd0c878885864f5fdc29be284d76906b45b (patch)
tree10975097f80927f4e9e05a1c3fc59f6af02f4988 /src
parent83cc748c8471cc88740e73e235282aa7734cffb2 (diff)
editSelect endpoint
this endpoint is similar to the view endpoint, but contains an edit button next to the challenges
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]