Insert election with uuid instead of auto-generated id
This commit is contained in:
@ -6,16 +6,16 @@ import (
|
||||
)
|
||||
|
||||
type VoterModelInterface interface {
|
||||
InsertMultiple(identities []string, electionID int) ([]int, error)
|
||||
CountByElection(electionID int) (int, error)
|
||||
Exists(voterIdentity string, electionID int) (bool, error)
|
||||
InsertMultiple(identities []string, electionID string) ([]int, error)
|
||||
CountByElection(electionID string) (int, error)
|
||||
Exists(voterIdentity string, electionID string) (bool, error)
|
||||
}
|
||||
|
||||
type VoterModel struct {
|
||||
DB *sql.DB
|
||||
}
|
||||
|
||||
func (v *VoterModel) InsertMultiple(identities []string, electionID int) ([]int, error) {
|
||||
func (v *VoterModel) InsertMultiple(identities []string, electionID string) ([]int, error) {
|
||||
tx, err := v.DB.Begin()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -53,7 +53,7 @@ func (v *VoterModel) InsertMultiple(identities []string, electionID int) ([]int,
|
||||
return voterIDs, nil
|
||||
}
|
||||
|
||||
func (v *VoterModel) CountByElection(electionID int) (int, error) {
|
||||
func (v *VoterModel) CountByElection(electionID string) (int, error) {
|
||||
// use a transaction to prevent race conditions
|
||||
tx, err := v.DB.Begin()
|
||||
if err != nil {
|
||||
@ -82,7 +82,7 @@ func (v *VoterModel) CountByElection(electionID int) (int, error) {
|
||||
return voterCount, nil
|
||||
}
|
||||
|
||||
func (v *VoterModel) Exists(voterIdentity string, electionID int) (bool, error) {
|
||||
func (v *VoterModel) Exists(voterIdentity string, electionID string) (bool, error) {
|
||||
query := `
|
||||
SELECT EXISTS (
|
||||
SELECT 1
|
||||
|
Reference in New Issue
Block a user