A new order

Exercise 3 of 4 in chapter 2 · 100 XP · 2 objectives checked by tests

Topics covered: Request bodyPOST201

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

  1. Add a Store method to the controller, wired to POST /deliveries.
  2. It reads client and quartier from the request's JSON body.
  3. It adds the delivery to the round, with the next number (the round has 4: the new one is number 5), not delivered yet.
  4. 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.