🗃️ gathers random questions on each call

Co-authored-by: haraldnilsen <harald_998@hotmail.com>
Signed-off-by: Sindre Kjelsrud <kjelsrudsindre@gmail.com>
This commit is contained in:
Sindre Kjelsrud 2024-01-14 12:19:37 +01:00
parent 91b027a64d
commit 35545070a9
Signed by untrusted user who does not match committer: sidski
GPG key ID: D2BBDF3EDE6BA9A6

View file

@ -44,12 +44,15 @@ func GetUserQuestions(respondentID int) ([]UserQuestions, error) {
log.Fatalf("Error connecting to the database: %v\n", err) log.Fatalf("Error connecting to the database: %v\n", err)
} }
getQuestionsStatement := `SELECT DISTINCT s.SpørsmålID, s.tekst getQuestionsStatement := `
FROM Spørsmål s SELECT s.SpørsmålID, s.tekst
LEFT JOIN Spørsmålsvar ss ON s.spørsmålID = ss.spørsmålID FROM Spørsmål s
LEFT JOIN SvarVurdering sv ON ss.svarID = sv.svarID AND sv.respondentID = $1 LEFT JOIN Spørsmålsvar ss ON s.spørsmålID = ss.spørsmålID
WHERE sv.vurderingID IS NULL LEFT JOIN SvarVurdering sv ON ss.svarID = sv.svarID AND sv.respondentID = $1
LIMIT 5` WHERE sv.vurderingID IS NULL
ORDER BY RANDOM()
LIMIT 5;
`
stmt, err := db.Prepare(getQuestionsStatement) stmt, err := db.Prepare(getQuestionsStatement)
if err != nil { if err != nil {