From 7e00f24fbd38a8a9a62e2881ad35a7f37ad8474d Mon Sep 17 00:00:00 2001 From: Sindre Kjelsrud Date: Thu, 4 Jan 2024 18:23:45 +0100 Subject: [PATCH] :construction: started on question-form Co-authored-by: haraldnilsen Signed-off-by: Sindre Kjelsrud --- backend/db/get_user_questions.go | 4 +++- .../src/api/{postFormData.ts => postUserformData.ts} | 8 ++++++-- frontend/src/routes/userform/+page.svelte | 10 ++++++++-- 3 files changed, 17 insertions(+), 5 deletions(-) rename frontend/src/api/{postFormData.ts => postUserformData.ts} (84%) diff --git a/backend/db/get_user_questions.go b/backend/db/get_user_questions.go index 056f2eb..c0e69ff 100644 --- a/backend/db/get_user_questions.go +++ b/backend/db/get_user_questions.go @@ -71,7 +71,9 @@ func GetUserQuestions(respondentID int) ([]UserQuestions, error) { return questionAnswers, err } - getAnswersStatement := `WITH TrueAnswer AS ( + getAnswersStatement := + ` + WITH TrueAnswer AS ( SELECT ss.svarID FROM SpørsmålSvar ss WHERE ss.spørsmålID = $1 diff --git a/frontend/src/api/postFormData.ts b/frontend/src/api/postUserformData.ts similarity index 84% rename from frontend/src/api/postFormData.ts rename to frontend/src/api/postUserformData.ts index 0eb818e..ef78c03 100644 --- a/frontend/src/api/postFormData.ts +++ b/frontend/src/api/postUserformData.ts @@ -1,9 +1,13 @@ -export const postFormData = ( +interface postUserformDataReponse { + respondentID: number; +} + +export const postUserformData = ( age: string, education: string, healthcare_personnel: string, gender: string -) => { +): postUserformDataReponse => { let url = "http://localhost:8080/submitform"; let personnel = healthcare_personnel == "Ja" ? true : false; diff --git a/frontend/src/routes/userform/+page.svelte b/frontend/src/routes/userform/+page.svelte index ed7f2fd..9bc70a5 100644 --- a/frontend/src/routes/userform/+page.svelte +++ b/frontend/src/routes/userform/+page.svelte @@ -2,12 +2,18 @@ import UserFormInput from "../../components/userform/UserFormInput.svelte"; import ArrowBack from "../../components/svg/ArrowBack.svelte"; import ButtonComponent from "../../components/userform/inputs/ButtonComponent.svelte"; - import { postFormData } from "../../api/postFormData"; + import { postUserformData } from "../../api/postUserformData"; let age: string = "18-20" let education: string = "PhD" let healthcare_personnel: string = "Ja" let gender: string = "Mann" + + const handleUserformSubmit = async (age: string, education: string, healthcare_personnel: string, gender: string) => { + const response = await postUserformData(age, education, healthcare_personnel, gender) + + await getUserQuestions(response.respondentID) + }
@@ -28,7 +34,7 @@
- postFormData(age, education, healthcare_personnel, gender)} /> + handleUserformSubmit(age, education, healthcare_personnel, gender)} />