🚑 critical changes before deployment

Co-authored-by: Sindre Kjelsrud <kjelsrudsindre@gmail.com>
This commit is contained in:
haraldnilsen 2024-01-14 20:39:43 +01:00
parent c1721e5e8e
commit 055fce482a
9 changed files with 24 additions and 17 deletions

View file

@ -54,6 +54,7 @@ func SetupDb() {
alder TEXT NOT NULL,
utdanningsgrad TEXT NOT NULL,
helsepersonell BOOL NOT NULL,
harlisens BOOL NOT NULL,
kjønn TEXT NOT NULL,
svartfør BOOL NOT NULL,
fylke TEXT NOT NULL,

View file

@ -53,7 +53,7 @@ func GetUserQuestions(respondentID int) ([]UserQuestions, error) {
FROM Spørsmålsvar ss
LEFT JOIN SvarVurdering sv ON ss.svarID = sv.svarID
GROUP BY ss.spørsmålID
HAVING COUNT(sv.vurderingID) < 10
HAVING COUNT(sv.vurderingID) < 3
) AS subquery ON s.spørsmålID = subquery.spørsmålID
WHERE subquery.spørsmålID IS NOT NULL
LIMIT 5

View file

@ -8,7 +8,7 @@ import (
_ "github.com/lib/pq"
)
func InsertUserData(age string, education string, healthcarepersonell bool, gender string, answeredbefore bool, county string, submitdate string) (int, error) {
func InsertUserData(age string, education string, healthcarepersonell bool, islicensed 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, svartfør, fylke, dato)
VALUES ($1, $2, $3, $4, $5, $6, $7)
INSERT INTO Respondent (alder, utdanningsgrad, helsepersonell, harlisens, kjønn, svartfør, fylke, dato)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
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, answeredbefore, county, submitdate).Scan(&respondentID)
err = stmt.QueryRow(age, education, healthcarepersonell, islicensed, gender, answeredbefore, county, submitdate).Scan(&respondentID)
if err != nil {
log.Fatalf("Error inserting userdata: %v\n", err)
}

View file

@ -14,6 +14,7 @@ type UserformData struct {
Age string `json:"age"`
Education string `json:"education"`
HealthcarePersonnel bool `json:"healthcare_personnel"`
IsLicensed bool `json:"is_licensed"`
Gender string `json:"gender"`
AnsweredBefore bool `json:"answered_before"`
County string `json:"county"`
@ -35,7 +36,7 @@ type Evaluation struct {
func main() {
router := gin.Default()
//router.Use(cors.Default())
// router.Use(cors.Default())
router.GET("/hello", func(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"hello":"world"})
@ -51,7 +52,7 @@ func main() {
}
// Capture both the ID and error returned from InsertData
respondentId, err := db.InsertUserData(requestBody.Age, requestBody.Education, requestBody.HealthcarePersonnel, requestBody.Gender, requestBody.AnsweredBefore, requestBody.County, requestBody.SubmitDate)
respondentId, err := db.InsertUserData(requestBody.Age, requestBody.Education, requestBody.HealthcarePersonnel, requestBody.IsLicensed, requestBody.Gender, requestBody.AnsweredBefore, requestBody.County, requestBody.SubmitDate)
if err != nil {
fmt.Print(err)
@ -148,6 +149,6 @@ func main() {
})
// Run the server on port 8080
//db.SetupDb()
// db.SetupDb()
router.Run(":8080")
}