Creating validator.go allowing us to validate received data from our endpoints. Updating errors.go adding failedValidationResponse method allowing us to deliver a StatusUnprocessableEntity error. Updating createMovieHandler with the use of our new validator package.
All checks were successful
Deploy Greenlight API / deploy (push) Successful in 53s

This commit is contained in:
Maxime Delporte
2025-10-28 11:04:18 +01:00
parent 040ace30ad
commit e5ddfa120f
3 changed files with 98 additions and 1 deletions

View File

@@ -51,3 +51,8 @@ func (app *application) methodNotAllowedResponse(w http.ResponseWriter, r *http.
func (app *application) badRequestResponse(w http.ResponseWriter, r *http.Request, err error) {
app.errorResponse(w, r, http.StatusBadRequest, err.Error())
}
// The errors parameter here has the type map[string]string, which is exactly the same as the errors map contained in our Validator type.
func (app *application) failedValidationResponse(w http.ResponseWriter, r *http.Request, errors map[string]string) {
app.errorResponse(w, r, http.StatusUnprocessableEntity, errors)
}