From 35545070a9adfe2dfcab88fdc786ddf284029dfe Mon Sep 17 00:00:00 2001 From: Sindre Kjelsrud Date: Sun, 14 Jan 2024 12:19:37 +0100 Subject: [PATCH] :card_file_box: gathers random questions on each call Co-authored-by: haraldnilsen Signed-off-by: Sindre Kjelsrud --- backend/cmd/db/get_user_questions.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/backend/cmd/db/get_user_questions.go b/backend/cmd/db/get_user_questions.go index 6d88162..b40ee8b 100644 --- a/backend/cmd/db/get_user_questions.go +++ b/backend/cmd/db/get_user_questions.go @@ -44,12 +44,15 @@ func GetUserQuestions(respondentID int) ([]UserQuestions, error) { log.Fatalf("Error connecting to the database: %v\n", err) } - getQuestionsStatement := `SELECT DISTINCT s.SpørsmålID, s.tekst - FROM Spørsmål s - LEFT JOIN Spørsmålsvar ss ON s.spørsmålID = ss.spørsmålID - LEFT JOIN SvarVurdering sv ON ss.svarID = sv.svarID AND sv.respondentID = $1 - WHERE sv.vurderingID IS NULL - LIMIT 5` + getQuestionsStatement := ` + SELECT s.SpørsmålID, s.tekst + FROM Spørsmål s + LEFT JOIN Spørsmålsvar ss ON s.spørsmålID = ss.spørsmålID + LEFT JOIN SvarVurdering sv ON ss.svarID = sv.svarID AND sv.respondentID = $1 + WHERE sv.vurderingID IS NULL + ORDER BY RANDOM() + LIMIT 5; + ` stmt, err := db.Prepare(getQuestionsStatement) if err != nil {