Bastien wanted to test the app: he ordered a delivery to “the Moon” (la-lune), with no customer name. It went into the round, and Yanis spent a good hour looking for the Moon.
Your mission
- At the start of
Store, validate the request:clientis required and is at least 2 characters long;quartieris required and must becroix-rousse,presqu-ile,guillotiereorconfluence. - An invalid order responds 422 with
{"erreurs": …}, the errors grouped by field, and does not join the round. - A valid order goes through as before.
Reminder
ctx.Request().Validate(rules) uses Laravel's syntax: required, in:a,b,c, email… As in Laravel, min:2 counts a string's characters and compares a number's value (Goravel still accepts min_len, the rule's old, deprecated name). Validate returns two values: the validator and an error. That's Go's way of reporting a problem, without exceptions: you check err right after the call, with if err != nil. Here, err doesn't mean the order is invalid, but that the validation could not run (a badly written rule, for example).
The verdict is in the validator: validator.Fails(), then validator.Errors().All(), the messages by field and by rule. Unlike Laravel, Goravel doesn't respond on its own: sending back the 422 is up to you.