Insert election with uuid instead of auto-generated id
This commit is contained in:
@ -7,9 +7,9 @@ import (
|
||||
)
|
||||
|
||||
type VoteModelInterface interface {
|
||||
Insert(voterIdentity string, electionId int, choiceText string, tokens int) (int, error)
|
||||
Exists(voterIdentity string, electionID int) (bool, error)
|
||||
GetByElection(electionID int) (*[]Vote, error)
|
||||
Insert(voterIdentity string, electionId string, choiceText string, tokens int) (int, error)
|
||||
Exists(voterIdentity string, electionID string) (bool, error)
|
||||
GetByElection(electionID string) (*[]Vote, error)
|
||||
}
|
||||
|
||||
type VoteModel struct {
|
||||
@ -18,13 +18,13 @@ type VoteModel struct {
|
||||
|
||||
type Vote struct {
|
||||
VoterIdentity string
|
||||
ElectionID int
|
||||
ElectionID string
|
||||
ChoiceText string
|
||||
Tokens int
|
||||
CreatedAt time.Time
|
||||
}
|
||||
|
||||
func (v *VoteModel) Insert(voterIdentity string, electionId int, choiceText string, tokens int) (int, error) {
|
||||
func (v *VoteModel) Insert(voterIdentity string, electionId string, choiceText string, tokens int) (int, error) {
|
||||
tx, err := v.DB.Begin()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
@ -47,7 +47,7 @@ func (v *VoteModel) Insert(voterIdentity string, electionId int, choiceText stri
|
||||
return int(voteId), nil
|
||||
}
|
||||
|
||||
func (v *VoteModel) Exists(voterIdentity string, electionID int) (bool, error) {
|
||||
func (v *VoteModel) Exists(voterIdentity string, electionID string) (bool, error) {
|
||||
var exists bool
|
||||
query := `
|
||||
SELECT EXISTS (
|
||||
@ -66,7 +66,7 @@ func (v *VoteModel) Exists(voterIdentity string, electionID int) (bool, error) {
|
||||
return exists, nil
|
||||
}
|
||||
|
||||
func (v *VoteModel) GetByElection(electionID int) (*[]Vote, error) {
|
||||
func (v *VoteModel) GetByElection(electionID string) (*[]Vote, error) {
|
||||
query := `
|
||||
SELECT voter_identity, election_id, choice_text, tokens, created_at
|
||||
FROM votes
|
||||
|
Reference in New Issue
Block a user