diff options
-rw-r--r-- | src/http.go | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/src/http.go b/src/http.go index 00f26a4..721ceb1 100644 --- a/src/http.go +++ b/src/http.go @@ -46,8 +46,29 @@ func createGetHandler(w http.ResponseWriter, r *http.Request) { readFileToResponse(w, "/create.html") } +// createPostHandler handles HTTP POST requests to the /create endpoint creating +// new challenges in the database func createPostHandler(w http.ResponseWriter, r *http.Request) { - log.Println("create POST") + + // parse the Post Request form + r.ParseForm() + + // Define the new challenge + newChallenge := Challenge{ + Name: r.Form.Get("challengeName"), + Description: r.Form.Get("challengeDescription"), + Flag: r.Form.Get("challengeFlag"), + Container: r.Form.Get("challengeContainer"), + Category: r.Form.Get("challengeCategory"), + Points: r.Form.Get("challengePoints"), + Static: r.Form.Get("challengeStatic"), + } + + // Create the new challenge in the database + err := newChallenge(newChallenge) + if err != nil { + log.Println(err) + } } // viewGetHandler returns a list of all challenges in the database |