In the app, a courier taps a delivery to see its details. Each delivery needs its own URL.
Your mission
- Add a
Showmethod to the controller, wired toGET /deliveries/{id}. - It looks through the round for the delivery whose
IDis the one in the URL, and sends it back as JSON. - An id that doesn't exist, or that isn't a number, responds 404 with
{"erreur": "delivery not found"}(erreur is French for “error”).
Reminder
ctx.Request().RouteInt("id") reads a route parameter and converts it to an int. Goravel also has RouteInt64, and Route for the raw string.
ctx.Response().Json(code, data) picks the HTTP status code. Goravel reuses the constants of Go's net/http package: http.StatusNotFound is 404, http.StatusCreated 201, http.StatusUnprocessableEntity 422. They read better than bare numbers.
In Go, return leaves the function right away, in the middle of a loop as anywhere else: the code after the loop only runs if nothing was found.