From 4f4317f59150588482779ab3e6f78cb4269bcd67 Mon Sep 17 00:00:00 2001 From: Emile Date: Sun, 20 Oct 2019 00:31:13 +0200 Subject: consistet naming for the db functions --- src/http.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'src/http.go') 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 + +} -- cgit 1.4.1