Move voting to a new endpoint

/election/{id}/votes
This commit is contained in:
2025-01-11 18:29:01 +01:00
parent 86d7d0e881
commit cad5cfe636
8 changed files with 186 additions and 100 deletions

View File

@ -22,11 +22,9 @@ func (app *application) serverError(w http.ResponseWriter, r *http.Request, err
func (app *application) clientError(w http.ResponseWriter, status int, message string) {
w.WriteHeader(status)
var response = api.ErrorResponse{
Code: http.StatusUnprocessableEntity,
Details: &map[string]interface{}{
"error": message,
},
Message: "There was an error in the request",
Code: status,
Details: nil,
Message: message,
}
json.NewEncoder(w).Encode(response)
}
@ -38,16 +36,7 @@ func (app *application) unprocessableEntityError(w http.ResponseWriter, v valida
Details: &map[string]interface{}{
"fields": v.FieldErrors,
},
Message: "Election data is invalid",
}
json.NewEncoder(w).Encode(response)
}
func (app *application) unprocessableEntityErrorSingle(w http.ResponseWriter, err error) {
w.WriteHeader(http.StatusUnprocessableEntity)
var response = api.ErrorResponse{
Code: http.StatusUnprocessableEntity,
Message: err.Error(),
Message: "Request data is invalid",
}
json.NewEncoder(w).Encode(response)
}