Add endpoint for POST /votes in openapi.yml
This commit is contained in:
@ -101,6 +101,11 @@ func randomVoterIdentity() string {
|
|||||||
return string(b)
|
return string(b)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type createVoteRequestWithValidator struct {
|
||||||
|
api.CreateVotesRequest
|
||||||
|
validator.Validator
|
||||||
|
}
|
||||||
|
|
||||||
func (app *application) createVote(w http.ResponseWriter, r *http.Request) {
|
func (app *application) createVote(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,8 @@ servers:
|
|||||||
tags:
|
tags:
|
||||||
- name: election
|
- name: election
|
||||||
description: Retrieve data related to elections
|
description: Retrieve data related to elections
|
||||||
|
- name: vote
|
||||||
|
description: Retrieve data related to votes
|
||||||
|
|
||||||
paths:
|
paths:
|
||||||
/election:
|
/election:
|
||||||
@ -50,6 +52,27 @@ paths:
|
|||||||
schema:
|
schema:
|
||||||
$ref: "#/components/schemas/ErrorResponse"
|
$ref: "#/components/schemas/ErrorResponse"
|
||||||
|
|
||||||
|
/votes:
|
||||||
|
post:
|
||||||
|
tags:
|
||||||
|
- vote
|
||||||
|
summary: Cast your votes for an election
|
||||||
|
operationId: createVotes
|
||||||
|
requestBody:
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: "#/components/schemas/CreateVotesRequest"
|
||||||
|
responses:
|
||||||
|
200:
|
||||||
|
description: Votes cast
|
||||||
|
422:
|
||||||
|
description: Unprocessable content
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: "#/components/schemas/ErrorResponse"
|
||||||
|
|
||||||
components:
|
components:
|
||||||
schemas:
|
schemas:
|
||||||
Election:
|
Election:
|
||||||
@ -194,9 +217,27 @@ components:
|
|||||||
items:
|
items:
|
||||||
type: string
|
type: string
|
||||||
minLength: 1
|
minLength: 1
|
||||||
maxItems: 1
|
|
||||||
uniqueItems: true
|
uniqueItems: true
|
||||||
|
|
||||||
|
CreateVotesRequest:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
voterIdentity:
|
||||||
|
type: string
|
||||||
|
minLength: 1
|
||||||
|
electionId:
|
||||||
|
type: integer
|
||||||
|
choices:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
properties:
|
||||||
|
choiceText:
|
||||||
|
type: string
|
||||||
|
minLength: 1
|
||||||
|
tokens:
|
||||||
|
type: integer
|
||||||
|
minimum: 1
|
||||||
|
|
||||||
ErrorResponse:
|
ErrorResponse:
|
||||||
type: object
|
type: object
|
||||||
required:
|
required:
|
||||||
|
@ -28,6 +28,16 @@ type CreateElectionResponse struct {
|
|||||||
VoterIdentities *[]string `json:"voterIdentities,omitempty"`
|
VoterIdentities *[]string `json:"voterIdentities,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CreateVotesRequest defines model for CreateVotesRequest.
|
||||||
|
type CreateVotesRequest struct {
|
||||||
|
Choices *[]struct {
|
||||||
|
ChoiceText *string `json:"choiceText,omitempty"`
|
||||||
|
Tokens *int `json:"tokens,omitempty"`
|
||||||
|
} `json:"choices,omitempty"`
|
||||||
|
ElectionId *int `json:"electionId,omitempty"`
|
||||||
|
VoterIdentity *string `json:"voterIdentity,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
// ErrorResponse defines model for ErrorResponse.
|
// ErrorResponse defines model for ErrorResponse.
|
||||||
type ErrorResponse struct {
|
type ErrorResponse struct {
|
||||||
// Code Machine-readable error code
|
// Code Machine-readable error code
|
||||||
@ -43,11 +53,17 @@ type ErrorResponse struct {
|
|||||||
// CreateElectionJSONRequestBody defines body for CreateElection for application/json ContentType.
|
// CreateElectionJSONRequestBody defines body for CreateElection for application/json ContentType.
|
||||||
type CreateElectionJSONRequestBody = CreateElectionRequest
|
type CreateElectionJSONRequestBody = CreateElectionRequest
|
||||||
|
|
||||||
|
// CreateVotesJSONRequestBody defines body for CreateVotes for application/json ContentType.
|
||||||
|
type CreateVotesJSONRequestBody = CreateVotesRequest
|
||||||
|
|
||||||
// ServerInterface represents all server handlers.
|
// ServerInterface represents all server handlers.
|
||||||
type ServerInterface interface {
|
type ServerInterface interface {
|
||||||
// Create a new election
|
// Create a new election
|
||||||
// (POST /election)
|
// (POST /election)
|
||||||
CreateElection(w http.ResponseWriter, r *http.Request)
|
CreateElection(w http.ResponseWriter, r *http.Request)
|
||||||
|
// Cast your votes for an election
|
||||||
|
// (POST /votes)
|
||||||
|
CreateVotes(w http.ResponseWriter, r *http.Request)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ServerInterfaceWrapper converts contexts to parameters.
|
// ServerInterfaceWrapper converts contexts to parameters.
|
||||||
@ -74,6 +90,21 @@ func (siw *ServerInterfaceWrapper) CreateElection(w http.ResponseWriter, r *http
|
|||||||
handler.ServeHTTP(w, r.WithContext(ctx))
|
handler.ServeHTTP(w, r.WithContext(ctx))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CreateVotes operation middleware
|
||||||
|
func (siw *ServerInterfaceWrapper) CreateVotes(w http.ResponseWriter, r *http.Request) {
|
||||||
|
ctx := r.Context()
|
||||||
|
|
||||||
|
handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
siw.Handler.CreateVotes(w, r)
|
||||||
|
}))
|
||||||
|
|
||||||
|
for _, middleware := range siw.HandlerMiddlewares {
|
||||||
|
handler = middleware(handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
handler.ServeHTTP(w, r.WithContext(ctx))
|
||||||
|
}
|
||||||
|
|
||||||
type UnescapedCookieParamError struct {
|
type UnescapedCookieParamError struct {
|
||||||
ParamName string
|
ParamName string
|
||||||
Err error
|
Err error
|
||||||
@ -189,6 +220,7 @@ func HandlerWithOptions(si ServerInterface, options StdHTTPServerOptions) http.H
|
|||||||
}
|
}
|
||||||
|
|
||||||
m.HandleFunc("POST "+options.BaseURL+"/election", wrapper.CreateElection)
|
m.HandleFunc("POST "+options.BaseURL+"/election", wrapper.CreateElection)
|
||||||
|
m.HandleFunc("POST "+options.BaseURL+"/votes", wrapper.CreateVotes)
|
||||||
|
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user