diff options
author | Emile <hanemile@protonmail.com> | 2019-10-19 18:05:44 +0200 |
---|---|---|
committer | Emile <hanemile@protonmail.com> | 2019-10-19 18:05:44 +0200 |
commit | dcb466bb1a939e618d84b1b7ccd19d76e1644aac (patch) | |
tree | 585aa35ff27569a90d7124fd3a421d735d94acdf | |
parent | c707aaaa4ddc94abfd9603af86c595cdbbb0ee2a (diff) |
implemented the create HTTP POST endpoint
-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 |