Compare commits
2 Commits
bbbdb637b0
...
f884e29ccd
Author | SHA1 | Date | |
---|---|---|---|
f884e29ccd
|
|||
1554743a95
|
5
.gitignore
vendored
5
.gitignore
vendored
@ -26,4 +26,7 @@ go.work.sum
|
|||||||
|
|
||||||
.idea
|
.idea
|
||||||
*.iml
|
*.iml
|
||||||
*.sqlite
|
*.sqlite
|
||||||
|
|
||||||
|
# exclude built binary
|
||||||
|
web
|
@ -23,7 +23,7 @@ func (app *application) createElection(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !isRequestValid(&request) {
|
if !request.isValid() {
|
||||||
app.unprocessableEntityError(w, request.Validator)
|
app.unprocessableEntityError(w, request.Validator)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -64,7 +64,7 @@ func (app *application) createElection(w http.ResponseWriter, r *http.Request) {
|
|||||||
w.Write(res)
|
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.NotBlank(r.Name), "name", "must not be blank")
|
||||||
r.CheckField(validator.GreaterThan(r.Tokens, 0), "tokens", "must be greater than 0")
|
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")
|
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)
|
return string(b)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (app *application) createVote(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -17,6 +17,7 @@ func (app *application) routes() http.Handler {
|
|||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
|
|
||||||
mux.HandleFunc("POST /election", app.createElection)
|
mux.HandleFunc("POST /election", app.createElection)
|
||||||
|
mux.HandleFunc("POST /vote", app.createVote)
|
||||||
|
|
||||||
standard := alice.New(app.recoverPanic, app.logRequest)
|
standard := alice.New(app.recoverPanic, app.logRequest)
|
||||||
return standard.Then(mux)
|
return standard.Then(mux)
|
||||||
|
Reference in New Issue
Block a user