From 8bd955855974f1ed5e4038dae76b77d77ac89061 Mon Sep 17 00:00:00 2001 From: Emile Date: Sat, 19 Oct 2019 23:15:31 +0200 Subject: implemented dbGetChallengeByUUID function --- src/db.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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 +} -- cgit 1.4.1