about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/http.go24
1 files changed, 21 insertions, 3 deletions
diff --git a/src/http.go b/src/http.go
index 721ceb1..630f9a6 100644
--- a/src/http.go
+++ b/src/http.go
@@ -7,6 +7,7 @@ import (
 	"io/ioutil"
 	"log"
 	"net/http"
+	"strconv"
 	"strings"
 
 	"github.com/gorilla/mux"
@@ -53,6 +54,22 @@ func createPostHandler(w http.ResponseWriter, r *http.Request) {
 	// parse the Post Request form
 	r.ParseForm()
 
+	points, err := strconv.ParseInt(r.Form.Get("challengePoints"), 10, 64)
+	if err != nil {
+		log.Println("Could not parse points: %v", err)
+		return
+	}
+
+	var static bool
+	if r.Form.Get("challengeStatic") == "on" {
+		static = true
+	} else if r.Form.Get("challengeStatic") == "off" {
+		static = false
+	} else {
+		log.Println("Could not parse static: %v", r.Form.Get("challengeStatic"))
+		return
+	}
+
 	// Define the new challenge
 	newChallenge := Challenge{
 		Name:        r.Form.Get("challengeName"),
@@ -60,14 +77,15 @@ func createPostHandler(w http.ResponseWriter, r *http.Request) {
 		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"),
+		Points:      int(points),
+		Static:      static,
 	}
 
 	// Create the new challenge in the database
-	err := newChallenge(newChallenge)
+	err = dbNewChallenge(newChallenge)
 	if err != nil {
 		log.Println(err)
+		return
 	}
 }