diff --git a/cmd/web/handlers.go b/cmd/web/handlers.go index 4e15e4b..d28717e 100644 --- a/cmd/web/handlers.go +++ b/cmd/web/handlers.go @@ -23,7 +23,7 @@ func (app *application) createElection(w http.ResponseWriter, r *http.Request) { return } - if !isRequestValid(&request) { + if !request.isValid() { app.unprocessableEntityError(w, request.Validator) return } @@ -64,7 +64,7 @@ func (app *application) createElection(w http.ResponseWriter, r *http.Request) { w.Write(res) } -func isRequestValid(r *createElectionRequestWithValidator) bool { +func (r *createElectionRequestWithValidator) isValid() bool { r.CheckField(validator.NotBlank(r.Name), "name", "must not be blank") r.CheckField(validator.GreaterThan(r.Tokens, 0), "tokens", "must be greater than 0") r.CheckField(validator.After(r.ExpiresAt, time.Now()), "expiresAt", "must expire in a future date") @@ -100,3 +100,7 @@ func randomVoterIdentity() string { } return string(b) } + +func (app *application) createVote(w http.ResponseWriter, r *http.Request) { + +} diff --git a/cmd/web/routes.go b/cmd/web/routes.go index 01d85db..fa75899 100644 --- a/cmd/web/routes.go +++ b/cmd/web/routes.go @@ -17,6 +17,7 @@ func (app *application) routes() http.Handler { mux := http.NewServeMux() mux.HandleFunc("POST /election", app.createElection) + mux.HandleFunc("POST /vote", app.createVote) standard := alice.New(app.recoverPanic, app.logRequest) return standard.Then(mux)