From 71354a182721f9c466a5622ce3da55c1ea7bed80 Mon Sep 17 00:00:00 2001 From: haraldnilsen Date: Wed, 10 Jan 2024 20:14:14 +0100 Subject: [PATCH] :card_file_box: new columns in usertable Co-authored-by: Sindre Kjelsrud --- backend/cmd/main.go | 5 ++++- backend/db/db.go | 5 ++++- backend/db/insert_user_data.go | 8 ++++---- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/backend/cmd/main.go b/backend/cmd/main.go index 2a2ae7e..8e889e5 100644 --- a/backend/cmd/main.go +++ b/backend/cmd/main.go @@ -16,6 +16,9 @@ type UserformData struct { Education string `json:"education"` HealthcarePersonnel bool `json:"healthcare_personnel"` Gender string `json:"gender"` + AnsweredBefore bool `json:"answered_before"` + County string `json:"county"` + SubmitDate string `json:"submit_date"` } type FormData struct { @@ -45,7 +48,7 @@ func main() { } // Capture both the ID and error returned from InsertData - respondentId, err := db.InsertUserData(requestBody.Age, requestBody.Education, requestBody.HealthcarePersonnel, requestBody.Gender) + respondentId, err := db.InsertUserData(requestBody.Age, requestBody.Education, requestBody.HealthcarePersonnel, requestBody.Gender, requestBody.AnsweredBefore, requestBody.County, requestBody.SubmitDate) if err != nil { fmt.Print(err) diff --git a/backend/db/db.go b/backend/db/db.go index 0ef8e8a..cad77d3 100644 --- a/backend/db/db.go +++ b/backend/db/db.go @@ -52,7 +52,10 @@ func SetupDb() { alder TEXT NOT NULL, utdanningsgrad TEXT NOT NULL, helsepersonell BOOL NOT NULL, - kjønn TEXT NOT NULL + kjønn TEXT NOT NULL, + svartfør BOOL NOT NULL, + fylke TEXT NOT NULL, + dato TEXT NOT NULL );`, `CREATE TABLE IF NOT EXISTS SvarVurdering ( vurderingID SERIAL PRIMARY KEY, diff --git a/backend/db/insert_user_data.go b/backend/db/insert_user_data.go index e543b4c..313d4e0 100644 --- a/backend/db/insert_user_data.go +++ b/backend/db/insert_user_data.go @@ -8,7 +8,7 @@ import ( _ "github.com/lib/pq" ) -func InsertUserData(age string, education string, healthcarepersonell bool, gender string) (int, error) { +func InsertUserData(age string, education string, healthcarepersonell bool, gender string, answeredbefore bool, county string, submitdate string) (int, error) { // Connection string psqlInfo := fmt.Sprintf("host=%s port=%d user=%s "+ "password=%s dbname=%s sslmode=disable", @@ -28,8 +28,8 @@ func InsertUserData(age string, education string, healthcarepersonell bool, gend } insertStatement := ` - INSERT INTO Respondent (alder, utdanningsgrad, helsepersonell, kjønn) - VALUES ($1, $2, $3, $4) + INSERT INTO Respondent (alder, utdanningsgrad, helsepersonell, kjønn, svartfør, fylke, dato) + VALUES ($1, $2, $3, $4, $5, $6, $7) RETURNING respondentID ` @@ -40,7 +40,7 @@ func InsertUserData(age string, education string, healthcarepersonell bool, gend defer stmt.Close() var respondentID int - err = stmt.QueryRow(age, education, healthcarepersonell, gender).Scan(&respondentID) + err = stmt.QueryRow(age, education, healthcarepersonell, gender, answeredbefore, county, submitdate).Scan(&respondentID) if err != nil { log.Fatalf("Error inserting userdata: %v\n", err) }