Update: Few issues to resolve see readme
this push will conclude the majority of pulls. this repos will now, not be actively be managed or any further code pushes will not be frequent.
This commit is contained in:
@@ -14,7 +14,7 @@ import (
|
||||
|
||||
func PollHandler(w http.ResponseWriter, r *http.Request) {
|
||||
username, _ := models.GetCurrentUserName(r)
|
||||
|
||||
|
||||
if r.Method == http.MethodGet {
|
||||
addressID := r.URL.Query().Get("address_id")
|
||||
if addressID == "" {
|
||||
@@ -27,7 +27,7 @@ func PollHandler(w http.ResponseWriter, r *http.Request) {
|
||||
var userID int
|
||||
fmt.Print(addressID, userID)
|
||||
err := models.DB.QueryRow(`
|
||||
SELECT a.address, ap.user_id
|
||||
SELECT a.address, ap.user_id
|
||||
FROM appointment AS ap
|
||||
JOIN address_database a ON a.address_id = ap.address_id
|
||||
WHERE ap.address_id = $1
|
||||
@@ -41,8 +41,8 @@ func PollHandler(w http.ResponseWriter, r *http.Request) {
|
||||
// Check if poll already exists for this address
|
||||
var pollID int
|
||||
err = models.DB.QueryRow(`
|
||||
SELECT poll_id
|
||||
FROM poll
|
||||
SELECT poll_id
|
||||
FROM poll
|
||||
WHERE address_id = $1 AND user_id = $2
|
||||
`, addressID, userID).Scan(&pollID)
|
||||
|
||||
@@ -53,7 +53,7 @@ func PollHandler(w http.ResponseWriter, r *http.Request) {
|
||||
VALUES ($1, $2, 'Door-to-Door Poll', 'Campaign polling questions', true)
|
||||
RETURNING poll_id
|
||||
`, userID, addressID).Scan(&pollID)
|
||||
|
||||
|
||||
if err != nil {
|
||||
log.Printf("Failed to create poll: %v", err)
|
||||
http.Error(w, "Failed to create poll", http.StatusInternalServerError)
|
||||
@@ -66,15 +66,15 @@ func PollHandler(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
utils.Render(w, "poll_form.html", map[string]interface{}{
|
||||
"Title": "Poll Questions",
|
||||
"IsAuthenticated": true,
|
||||
"ShowAdminNav": true,
|
||||
"UserName": username,
|
||||
"ActiveSection": "appointments",
|
||||
"PollID": pollID,
|
||||
"AddressID": addressID,
|
||||
"Address": address,
|
||||
"PageIcon": "fas fa-poll",
|
||||
"Title": "Poll Questions",
|
||||
"IsAuthenticated": true,
|
||||
"ShowVolunteerNav": true,
|
||||
"ActiveSection": "schedule",
|
||||
"UserName": username,
|
||||
"PollID": pollID,
|
||||
"AddressID": addressID,
|
||||
"Address": address,
|
||||
"PageIcon": "fas fa-poll",
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -123,35 +123,35 @@ func PollHandler(w http.ResponseWriter, r *http.Request) {
|
||||
// Insert poll response
|
||||
_, err = models.DB.Exec(`
|
||||
INSERT INTO poll_response (
|
||||
poll_id, respondent_postal_code, question1_voted_before,
|
||||
poll_id, respondent_postal_code, question1_voted_before,
|
||||
question2_vote_again, question3_lawn_signs, question4_banner_signs,
|
||||
question5_thoughts, question6_donation_amount
|
||||
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
|
||||
`, pollID, postalCode, question1VotedBefore, question2VoteAgain,
|
||||
question3LawnSigns, question4BannerSigns, question5Thoughts, question6donation)
|
||||
`, pollID, postalCode, question1VotedBefore, question2VoteAgain,
|
||||
question3LawnSigns, question4BannerSigns, question5Thoughts, question6donation)
|
||||
|
||||
if err != nil {
|
||||
fmt.Print(err)
|
||||
http.Error(w, "Failed to save poll response", http.StatusInternalServerError)
|
||||
return
|
||||
}else{
|
||||
} else {
|
||||
_, err := models.DB.Exec(`
|
||||
UPDATE address_database
|
||||
SET visited_validated = true
|
||||
UPDATE address_database
|
||||
SET visited_validated = true
|
||||
WHERE address_id IN (
|
||||
SELECT address_id
|
||||
FROM poll
|
||||
SELECT address_id
|
||||
FROM poll
|
||||
WHERE poll_id = $1
|
||||
)
|
||||
`, pollID)
|
||||
if err != nil {
|
||||
fmt.Print(err)
|
||||
http.Error(w, "Failed to save poll response", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
http.Redirect(w, r, "/volunteer/Addresses", http.StatusSeeOther)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user