diff options
Diffstat (limited to 'src/db.go')
-rw-r--r-- | src/db.go | 16 |
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 +} |