Delivered!

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

Topics covered: Query builderUpdatePATCH204

Margot's last request: once a courier has dropped off a parcel, they tap “Delivered” in the app, and the app files it with the finished deliveries.

Your mission

  1. Complete the controller's Livrer method (“deliver”): it marks the delivery from the URL as delivered (livree set to true) in the table.
  2. It responds 204, with no content.
  3. An unknown number responds 404 with {"erreur": "delivery not found"}.
  4. Wire it to PATCH /api/deliveries/{id}/delivered, in the API group.

Reminder

Update(columns) changes the rows selected by the query, like DB::table()->where()->update() in Laravel. It returns a *db.Result whose RowsAffected tells how many rows changed: that's how you know, without reading the table again, whether the delivery existed.

PATCH changes part of a resource, where PUT replaces it entirely. A 204 No Content response says “done” without sending anything back: the app will read the delivery again if it needs to.

The round is complete: routes, controllers, a view, validation, middleware and a database. You've covered what a web framework does day to day, in Go.