Compare commits
2 Commits
7ab27a947e
...
e8ced857e0
Author | SHA1 | Date | |
---|---|---|---|
e8ced857e0
|
|||
2f13d7a76a
|
@ -92,10 +92,7 @@ func (app *application) CreateElection(w http.ResponseWriter, r *http.Request) {
|
||||
randomIdentity := randomVoterIdentity()
|
||||
voterIdentities = append(voterIdentities, randomIdentity)
|
||||
}
|
||||
_, err := app.voters.InsertMultiple(voterIdentities, electionId)
|
||||
if err != nil {
|
||||
app.serverError(w, r, err)
|
||||
}
|
||||
go app.voters.InsertMultiple(voterIdentities, electionId)
|
||||
|
||||
res, err = json.Marshal(api.CreateElectionResponse{VoterIdentities: &voterIdentities})
|
||||
if err != nil {
|
||||
|
@ -22,7 +22,6 @@ func (v *VoterModel) InsertMultiple(identities []string, electionID int) ([]int,
|
||||
}
|
||||
defer tx.Rollback()
|
||||
|
||||
// Prepare the statement once to reuse
|
||||
stmt, err := tx.Prepare(`
|
||||
INSERT INTO voters (identity, election_id)
|
||||
VALUES (?, ?)`)
|
||||
@ -31,10 +30,8 @@ func (v *VoterModel) InsertMultiple(identities []string, electionID int) ([]int,
|
||||
}
|
||||
defer stmt.Close()
|
||||
|
||||
// Store all voter IDs
|
||||
voterIDs := make([]int, 0, len(identities))
|
||||
|
||||
// Execute statement for each identity
|
||||
for _, identity := range identities {
|
||||
result, err := stmt.Exec(identity, electionID)
|
||||
if err != nil {
|
||||
|
@ -61,6 +61,17 @@
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<div v-if="createdElectionId > 0" class="election-info">
|
||||
<h2>Election Created Successfully</h2>
|
||||
<div class="info-container">
|
||||
<span class="info-label">Election ID:</span>
|
||||
<span class="info-value">{{ createdElectionId }}</span>
|
||||
<button @click="copyElectionId" class="copy-btn">
|
||||
Copy
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="voterIdentities.length > 0" class="voter-codes">
|
||||
<h2>Voter Access Codes</h2>
|
||||
<div class="codes-container">
|
||||
@ -95,6 +106,7 @@
|
||||
expiresAt: "",
|
||||
choices: ["", ""] // Start with two empty choices
|
||||
},
|
||||
createdElectionId: 0,
|
||||
voterIdentities: []
|
||||
};
|
||||
},
|
||||
@ -138,7 +150,12 @@
|
||||
},
|
||||
body: JSON.stringify(payload)
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(response => {
|
||||
const locationHeader = response.headers.get('Location');
|
||||
this.createdElectionId = locationHeader.replace('/election/', '');
|
||||
|
||||
return response.json();
|
||||
})
|
||||
.then(data => {
|
||||
this.voterIdentities = data.voterIdentities;
|
||||
})
|
||||
|
@ -147,6 +147,35 @@ button:hover {
|
||||
margin-top: 1rem;
|
||||
}
|
||||
|
||||
.election-info {
|
||||
margin-top: 2rem;
|
||||
}
|
||||
|
||||
.election-info h2 {
|
||||
margin-bottom: 1.5rem;
|
||||
color: var(--text-color);
|
||||
font-size: 1.5rem;
|
||||
}
|
||||
|
||||
.info-container {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 0.75rem;
|
||||
background: var(--background-color);
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.info-label {
|
||||
font-weight: 500;
|
||||
margin-right: 1rem;
|
||||
}
|
||||
|
||||
.info-value {
|
||||
font-family: monospace;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
@media (max-width: 640px) {
|
||||
.container {
|
||||
padding: 0;
|
||||
|
Reference in New Issue
Block a user