From 9078b7429abc1b567bf4bc7e8b9466655ce9ebb1 Mon Sep 17 00:00:00 2001 From: Emile Date: Sat, 19 Oct 2019 18:28:13 +0200 Subject: implemented the dbNewChallenge function --- src/db.go | 16 ++++++++++++++-- 1 file 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 } -- cgit 1.4.1