about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorEmile <hanemile@protonmail.com>2019-10-19 18:28:13 +0200
committerEmile <hanemile@protonmail.com>2019-10-19 18:28:13 +0200
commit9078b7429abc1b567bf4bc7e8b9466655ce9ebb1 (patch)
tree3c031dd08e7f00e06e5907fe577f30626265ffbc /src
parentdcb466bb1a939e618d84b1b7ccd19d76e1644aac (diff)
implemented the dbNewChallenge function
Diffstat (limited to 'src')
-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
 }