Add page to create an election
This commit is contained in:
@ -87,7 +87,7 @@ func (app *application) CreateElection(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
var res []byte
|
||||
if request.AreVotersKnown {
|
||||
voterIdentities := make([]string, 0, request.MaxVoters)
|
||||
voterIdentities := make([]string, 0, request.MaxVoters) // TODO: this is way too slow
|
||||
for i := 0; i < request.MaxVoters; i++ {
|
||||
randomIdentity := randomVoterIdentity()
|
||||
_, err := app.voters.Insert(randomIdentity, electionId)
|
||||
|
@ -48,7 +48,7 @@ func main() {
|
||||
Addr: addr,
|
||||
Handler: app.routes(),
|
||||
ErrorLog: slog.NewLogLogger(logger.Handler(), slog.LevelError),
|
||||
IdleTimeout: time.Minute,
|
||||
IdleTimeout: 6 * time.Minute,
|
||||
ReadTimeout: 5 * time.Second,
|
||||
WriteTimeout: 10 * time.Second,
|
||||
}
|
||||
|
@ -133,107 +133,6 @@ paths:
|
||||
|
||||
components:
|
||||
schemas:
|
||||
Election:
|
||||
type: object
|
||||
required:
|
||||
- id
|
||||
- name
|
||||
- tokens
|
||||
- areVotersKnown
|
||||
- maxVoters
|
||||
- expiresAt
|
||||
properties:
|
||||
id:
|
||||
type: integer
|
||||
format: int64
|
||||
readOnly: true
|
||||
name:
|
||||
type: string
|
||||
minLength: 1
|
||||
tokens:
|
||||
type: integer
|
||||
minimum: 1
|
||||
areVotersKnown:
|
||||
type: boolean
|
||||
maxVoters:
|
||||
type: integer
|
||||
minimum: 0
|
||||
description: Must be greater than 0 when voters are known
|
||||
createdAt:
|
||||
type: string
|
||||
format: date-time
|
||||
readOnly: true
|
||||
expiresAt:
|
||||
type: string
|
||||
format: date-time
|
||||
choices:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/components/schemas/Choice'
|
||||
voters:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/components/schemas/Voter'
|
||||
|
||||
Choice:
|
||||
type: object
|
||||
required:
|
||||
- text
|
||||
- electionId
|
||||
properties:
|
||||
text:
|
||||
type: string
|
||||
minLength: 1
|
||||
electionId:
|
||||
type: integer
|
||||
format: int64
|
||||
|
||||
Voter:
|
||||
type: object
|
||||
required:
|
||||
- identity
|
||||
- electionId
|
||||
properties:
|
||||
identity:
|
||||
type: string
|
||||
minLength: 1
|
||||
description: When voters are known, passcodes will be pre-generated
|
||||
electionId:
|
||||
type: integer
|
||||
format: int64
|
||||
votes:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/components/schemas/Vote'
|
||||
|
||||
Vote:
|
||||
type: object
|
||||
required:
|
||||
- voterIdentity
|
||||
- electionId
|
||||
properties:
|
||||
voterIdentity:
|
||||
type: string
|
||||
minLength: 1
|
||||
electionId:
|
||||
type: integer
|
||||
format: int64
|
||||
choiceText:
|
||||
type: string
|
||||
nullable: true
|
||||
tokens:
|
||||
type: integer
|
||||
minimum: 1
|
||||
nullable: true
|
||||
calculatedVoteCount:
|
||||
type: integer
|
||||
readOnly: true
|
||||
description: Calculated as floor(sqrt(tokens))
|
||||
createdAt:
|
||||
type: string
|
||||
format: date-time
|
||||
readOnly: true
|
||||
|
||||
CreateElectionRequest:
|
||||
type: object
|
||||
required:
|
||||
|
Reference in New Issue
Block a user