Shopkeepers call Margot to order a delivery, and Margot types everything on her phone. She would like the app to record the order directly.
Your mission
- Add a
Storemethod to the controller, wired toPOST /deliveries. - It reads
clientandquartierfrom the request's JSON body. - It adds the delivery to the round, with the next number (the round has 4: the new one is number 5), not delivered yet.
- It responds 201 with the new delivery as JSON.
The “Requests” tab has an order ready to send.
Reminder
ctx.Request().Input("client") reads a field, whether it comes from a JSON body, a form or the query string. To fill a struct in one go, there is also ctx.Request().Bind(&livraison).
In Go, a value you don't provide gets its zero value: 0 for a number, "" for a string, false for a boolean. So Livraison{Client: "…"} leaves Livree at false.
The round lives in memory: it starts again from its four deliveries every time the application restarts. In chapter 4, it moves into a database.