about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/db.go16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/db.go b/src/db.go
index 9e06493..cb65979 100644
--- a/src/db.go
+++ b/src/db.go
@@ -78,6 +78,18 @@ func getAllChallenges(db *sql.DB) []Challenge {
 	return challenges
 }
 
-func newChallenge(challenge Challenge) error {
-	// do magic here
+// dbNewChallenge inserts the given challenge into the database
+func dbNewChallenge(challenge Challenge) error {
+
+	// build the query to be executed
+	query := fmt.Sprintf("INSERT INTO challenges(name, description, flag, container, category, points, static) VALUES ($1, $2, $3, $4, $5, $6, $7)")
+
+	// execute the query with the challenge values given
+	_, err := db.Exec(query, challenge.Name, challenge.Description, challenge.Flag, challenge.Container, challenge.Category, challenge.Points, challenge.Static)
+
+	// handle errors
+	if err != nil {
+		return err
+	}
+	return nil
 }