summaryrefslogtreecommitdiff
path: root/poll.go
diff options
context:
space:
mode:
Diffstat (limited to 'poll.go')
-rw-r--r--poll.go24
1 files changed, 22 insertions, 2 deletions
diff --git a/poll.go b/poll.go
index 275aa21..0952cd7 100644
--- a/poll.go
+++ b/poll.go
@@ -85,7 +85,7 @@ func getPollFromId(db *sqlite3.Conn, id int) (Poll, error) {
sql := "SELECT * FROM polls WHERE id = $a"
s, err := db.Query(sql, args)
row := make(sqlite3.RowMap)
-
+
for ; err == nil ; err = s.Next() {
var rowid int64
s.Scan(&rowid, row) // Assigns 1st column to rowid, the rest to row
@@ -123,5 +123,25 @@ func deletePoll(db *sqlite3.Conn, id int, nick string) error {
return errors.New("You do not have permission to delete this poll")
}
+}
+
+func hasUserVotedInPoll(db *sqlite3.Conn, poll Poll, user User) bool {
-} \ No newline at end of file
+ args := sqlite3.NamedArgs{"$a": poll.id, "$b": user.id}
+ sql := "SELECT count(*) FROM votes WHERE poll_id = $a AND user_id = $b"
+ s, err := db.Query(sql, args)
+
+ for ; err == nil ; err = s.Next() {
+ var count int64
+ s.Scan(&count) // Assigns 1st column to rowid, the rest to row
+
+ if (count == 0) {
+ return false
+ } else {
+ return true
+ }
+ }
+
+ //Not sure why we'd get here, but we probably don't want to record a vote if we did
+ return true
+}