about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEmile <hanemile@protonmail.com>2019-10-19 23:15:31 +0200
committerEmile <hanemile@protonmail.com>2019-10-19 23:15:31 +0200
commit8bd955855974f1ed5e4038dae76b77d77ac89061 (patch)
treed9f5b00953a3199839aeefbf6705f0ef6a0a30a8
parente6082efddfcf7e304429a9ab8dd7b15d71c59c52 (diff)
implemented dbGetChallengeByUUID function
-rw-r--r--src/db.go16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/db.go b/src/db.go
index 7662faa..da58951 100644
--- a/src/db.go
+++ b/src/db.go
@@ -104,3 +104,19 @@ func editChallengeUUID(uuid string, updatedChallenge Challenge) error {
 
 	return nil
 }
+
+// dbGetChallengeByUUID returns the challenge with the given UUID from the database
+func dbGetChallengeByUUID(uuid string) (Challenge, error) {
+	// build the query to be executed
+	query := fmt.Sprintf("SELECT uuid, name, description, flag, container, category, points, static FROM challenges WHERE uuid::text= '%s'", uuid)
+
+	challenge := Challenge{}
+
+	// execute the query storing the values in the challenge struct defined above
+	err := db.QueryRow(query).Scan(&challenge.UUID, &challenge.Name, &challenge.Description, &challenge.Flag, &challenge.Container, &challenge.Category, &challenge.Points, &challenge.Static)
+
+	if err != nil {
+		return Challenge{}, err
+	}
+	return challenge, nil
+}