Add endpoint for POST /votes in openapi.yml
This commit is contained in:
@ -28,6 +28,16 @@ type CreateElectionResponse struct {
|
||||
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.
|
||||
type ErrorResponse struct {
|
||||
// Code Machine-readable error code
|
||||
@ -43,11 +53,17 @@ type ErrorResponse struct {
|
||||
// CreateElectionJSONRequestBody defines body for CreateElection for application/json ContentType.
|
||||
type CreateElectionJSONRequestBody = CreateElectionRequest
|
||||
|
||||
// CreateVotesJSONRequestBody defines body for CreateVotes for application/json ContentType.
|
||||
type CreateVotesJSONRequestBody = CreateVotesRequest
|
||||
|
||||
// ServerInterface represents all server handlers.
|
||||
type ServerInterface interface {
|
||||
// Create a new election
|
||||
// (POST /election)
|
||||
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.
|
||||
@ -74,6 +90,21 @@ func (siw *ServerInterfaceWrapper) CreateElection(w http.ResponseWriter, r *http
|
||||
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 {
|
||||
ParamName string
|
||||
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+"/votes", wrapper.CreateVotes)
|
||||
|
||||
return m
|
||||
}
|
||||
|
Reference in New Issue
Block a user