about summary refs log tree commit diff
path: root/src/http.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/http.go')
-rw-r--r--src/http.go14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/http.go b/src/http.go
index 8cbcf01..fe38a8e 100644
--- a/src/http.go
+++ b/src/http.go
@@ -30,6 +30,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("/api/getChallenges", getChallenges).Methods("GET")
 
 	return http.Server{
 		Addr:    fmt.Sprintf("0.0.0.0:%d", *port),
@@ -93,7 +94,7 @@ func createPostHandler(w http.ResponseWriter, r *http.Request) {
 // viewGetHandler returns a list of all challenges in the database
 func viewGetHandler(w http.ResponseWriter, r *http.Request) {
 	// get all challenges from the db
-	challs := getAllChallenges(db)
+	challs := dbGetAllChallenges(db)
 
 	// define a challenges struct storing the challenges.
 	// This struct can be used in a template
@@ -187,7 +188,7 @@ func editPostHandler(w http.ResponseWriter, r *http.Request) {
 	}
 
 	// update the challenge in the database
-	editChallengeUUID(r.Form.Get("challengeUUID"), editedChallenge)
+	dbEditChallengeUUID(r.Form.Get("challengeUUID"), editedChallenge)
 	log.Println("done editing challenge!")
 
 	http.Redirect(w, r, "/edit", http.StatusSeeOther)
@@ -205,3 +206,12 @@ func readFileToResponse(w http.ResponseWriter, path string) {
 		w.Write([]byte(contents))
 	}
 }
+
+// getChallenges returns all challenges
+func getChallenges(w http.ResponseWriter, r *http.Request) {
+	// Steps:
+	// - get all challenges from the database
+	// - marshal the challenges to json
+	// - return the json
+
+}